{"id":204,"date":"2020-08-10T15:50:02","date_gmt":"2020-08-10T14:50:02","guid":{"rendered":"http:\/\/ri.itservices.manchester.ac.uk\/csf4\/?page_id=204"},"modified":"2024-07-10T11:20:40","modified_gmt":"2024-07-10T10:20:40","slug":"linux-commands","status":"publish","type":"page","link":"https:\/\/ri.itservices.manchester.ac.uk\/csf4\/getting-started\/linux-commands\/","title":{"rendered":"Linux Commands"},"content":{"rendered":"<p>The CSF runs the Linux operating system. Interaction with the system is done by typing commands into a <em>terminal <\/em>program. This can be a little daunting at first. For Windows users, navigating around your directories (folders) and managing your files must be done with commands. The table below contains the basic Linux commands you will need to know to use the CSF.<\/p>\n<p>Commands specific to the <a href=\"\/csf4\/batch\/\">batch system<\/a> (not a default part of Linux) are covered in other parts of our documentation. Other useful Linux commands may also be mentioned elsewhere.<\/p>\n<table class=\"striped\">\n<tr>\n<th style width=26%>Commands<\/th>\n<th>Description<\/th>\n<\/tr>\n<tr>\n<td>\nTerminology 1: Directory (or <em>dir<\/em>)<br \/>\nTerminology 2: Home directory (or <em>home<\/em>)\n<\/td>\n<td>\nLinux <em>directories<\/em> are the same as Windows <em>folders<\/em>.<br \/>\nYour private directory similar to <em>My Documents<\/em>. It is also the directory you start <em>in<\/em> upon login.\n<\/td>\n<\/tr>\n<tr>\n<td>\n<code>cd dir1<\/code><br \/>\n<code>cd ~\/dir1\/dir2<\/code><br \/>\n<code>cd ~\/scratch<\/code><br \/>\n<code>cd ..<\/code><br \/>\n<code>cd<\/code>\n<\/td>\n<td>\nChange directory (go into <code>dir1<\/code> which is located in the current dir).<br \/>\nGo into <code>dir2<\/code> in <code>dir1<\/code> in your <em>home<\/em> dir (<code>~<\/code> is shorthand for <emphasis>home<\/emphasis>)<br \/>\nGo into your <em>scratch<\/em> directory (CSF-specific)<br \/>\nGo up to parent directory (e.g., from <code>~\/dir1\/dir2<\/code> to <code>~\/dir1<\/code>)<br \/>\nGo back to <emphasis>home<\/emphasis> (useful if you become lost)\n<\/td>\n<\/tr>\n<tr>\n<td>\n<code>pwd<\/code>\n<\/td>\n<td>\nLost? Print Working Directory (display your current location &#8211; the folder you are currently working in)\n<\/td>\n<\/tr>\n<tr>\n<td>\n<code>ls<\/code><br \/>\n<code>ls -lh<\/code><br \/>\n<code>ls -lh file1 dirA<\/code><br \/>\n<code>ls -lh dirA\/*.dat<\/code>\n<\/td>\n<td>\nList content (names of files and directories) of current directory<br \/>\nList in long form (dates, file sizes, names) current directory<br \/>\nList in long form (dates, file sizes, names) specified files, directories \u2026<br \/>\nList in long form all files ending in <code>.dat<\/code> in directory <code>dirA<\/code>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<code>mkdir dirA<\/code><br \/>\n<code>mkdir -p dirA\/dirB\/dirC<\/code>\n<\/td>\n<td>\nMake directory named <code>dirA<\/code> (in the current directory)<br \/>\nMake directory tree <code>dirA\/dirB\/dirC<\/code> (dirB inside dirA &#8230;) including dirs that don&#8217;t already exist\n<\/td>\n<\/tr>\n<tr>\n<td>\n<code>cp fileA fileB<\/code><br \/>\n<code>cp fileA dirA<\/code><br \/>\n<code>cp fileA ~\/scratch<\/code>\n<\/td>\n<td>\nCopy (duplicate) a file (copy <code>fileA<\/code> to a new file <code>fileB<\/code>)<br \/>\nCopy (duplicate) a file into the directory named <code>dirA<\/code><br \/>\nCopy (duplicate) a file into your <em>scratch<\/em> directory (CSF-specific)\n<\/td>\n<\/tr>\n<tr>\n<td>\n<code>mv fileC fileD<\/code><br \/>\n<code>mv fileE dirA<\/code><br \/>\n<code>mv fileF dirA\/fileG<\/code>\n<\/td>\n<td>\nRename a file (from <code>fileC<\/code> to <code>fileD<\/code>). Works for directories too.<br \/>\nMove <code>fileE<\/code> into sub-directory <code>dirA<\/code> (<code>dirA<\/code> must exist)<br \/>\nMove <code>fileF<\/code> AND rename it all in one go (<code>dirA<\/code> must exist)\n<\/td>\n<\/tr>\n<tr>\n<td>\n<code>rm fileH<\/code><br \/>\n<code>rm dirA\/fileB<\/code>\n<\/td>\n<td>\nDelete (remove) a file (caution!!)<br \/>\nDelete (remove) a file named <code>fileB<\/code> from <code>dirA<\/code>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<code><span class=\"err\">rm -rf dir1<\/span><\/code>\n<\/td>\n<td>\nDelete directory and all files (and other sub-dirs) in there (<span class=\"err\">caution!!!!!<\/span>)\n<\/td>\n<\/tr>\n<tr>\n<td>\n<code>gzip bigfile<\/code><br \/>\n&nbsp;<br \/>\n<code>gunzip bigfile.gz<\/code>\n<\/td>\n<td>\nCompress a file (becomes <code>bigfile.gz<\/code>) to make better use of diskspace. Text files usually compress well.<br \/>\nUncompress previously compressed file (becomes <code>bigfile<\/code>).\n<\/td>\n<\/tr>\n<tr>\n<td>\n<code>less file1<\/code><br \/>\n<code>zless file2.gz<\/code>\n<\/td>\n<td>\nDisplay the content of <code>file1<\/code> (text file) a page at a time on screen.<br \/>\nIf you&#8217;ve compressed <code>file2<\/code> with <code>gzip<\/code>, no need to uncompress first.<br \/>\nPress <code>space<\/code> to page down through a long file<br \/>\nPress <code>return<\/code> to scroll down a line at a time<br \/>\nPress <code>b<\/code> to scroll back up a page<br \/>\nPress <code>G<\/code> to go to end of file<br \/>\nPress <code>q<\/code> to quit\/exit\n<\/td>\n<\/tr>\n<tr>\n<td>\n<code>cat file1<\/code><br \/>\n<code>zcat file2.gz<\/code>\n<\/td>\n<td>\nDump entire file to screen (a quick way to look at text files).<br \/>\nIf you&#8217;ve compress <code>file2<\/code> with <code>gzip<\/code>, no need to uncompress first.\n<\/td>\n<\/tr>\n<tr>\n<td>\n<code>gedit file1\n<\/td>\n<td>\nEdit <code>file1<\/code> using a simple graphical text editor (similar to notepad on Windows). Make sure you have <a href=\"\/csf3\/getting-started\/connecting\/gui-apps\/\">logged in enabling the ability to open graphical programs<\/a><br \/>\non the CSF so that they display a window on your computer.\n<\/td>\n<\/tr>\n<tr>\n<td>\n<code>file filenameA<\/code>\n<\/td>\n<td>\nTry to tell us what type of data is in <code>filenameA<\/code>. Useful to determine the output of some program where you are not sure what type of output it has generated. For example:<br \/>\n<code>file output.dat<\/code><br \/>\nMight be <code>ASCII text<\/code> (so we can look at it with <code>less<\/code> or <code>gedit<\/code>)<br \/>\nor might be <code>data<\/code> (you'll need some other program to read it)\n<\/td>\n<\/tr>\n<tr>\n<td>\n<code>du -sh .<\/code>\n<\/td>\n<td>\nHow much disk space is current directory (all files and subdirs) using?\n<\/td>\n<\/tr>\n<tr>\n<td>\n<code>df -h .<\/code>\n<\/td>\n<td>\nHow much free space is there in the current area?\n<\/td>\n<\/tr>\n<\/table>\n<h2>Further Information<\/h2>\n<p>If you would like to learn more we recommend the following training materials<\/p>\n<ul>\n<li><a href=\"http:\/\/www.training.itservices.manchester.ac.uk\/uom\/RAC\/UNIX\/Course\/ITS_RUNIX\/presentation.html\">IT Services online Intro to Unix\/Linux course<\/a><\/li>\n<li><a href=\"http:\/\/www.ee.surrey.ac.uk\/Teaching\/Unix\/\">Beginners guide to UNIX\/Linux<\/a> (University of Surrey)<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The CSF runs the Linux operating system. Interaction with the system is done by typing commands into a terminal program. This can be a little daunting at first. For Windows users, navigating around your directories (folders) and managing your files must be done with commands. The table below contains the basic Linux commands you will need to know to use the CSF. Commands specific to the batch system (not a default part of Linux) are.. <a href=\"https:\/\/ri.itservices.manchester.ac.uk\/csf4\/getting-started\/linux-commands\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"parent":19,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-204","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf4\/wp-json\/wp\/v2\/pages\/204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf4\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf4\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf4\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf4\/wp-json\/wp\/v2\/comments?post=204"}],"version-history":[{"count":17,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf4\/wp-json\/wp\/v2\/pages\/204\/revisions"}],"predecessor-version":[{"id":1300,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf4\/wp-json\/wp\/v2\/pages\/204\/revisions\/1300"}],"up":[{"embeddable":true,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf4\/wp-json\/wp\/v2\/pages\/19"}],"wp:attachment":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf4\/wp-json\/wp\/v2\/media?parent=204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}