<?xml version="1.0" encoding="utf-8"?><!DOCTYPE article  PUBLIC '-//OASIS//DTD DocBook XML V4.4//EN'  'http://www.docbook.org/xml/4.4/docbookx.dtd'><article><articleinfo><title>unixsurvivalguide</title><revhistory><revision><revnumber>52</revnumber><date>2020-11-23 15:57:18</date><authorinitials>OlafHauk</authorinitials></revision><revision><revnumber>51</revnumber><date>2017-01-04 13:05:39</date><authorinitials>ClareCook</authorinitials></revision><revision><revnumber>50</revnumber><date>2017-01-04 13:03:54</date><authorinitials>ClareCook</authorinitials></revision><revision><revnumber>49</revnumber><date>2017-01-04 12:59:40</date><authorinitials>ClareCook</authorinitials></revision><revision><revnumber>48</revnumber><date>2017-01-04 12:54:17</date><authorinitials>ClareCook</authorinitials></revision><revision><revnumber>47</revnumber><date>2017-01-04 12:48:57</date><authorinitials>ClareCook</authorinitials></revision><revision><revnumber>46</revnumber><date>2017-01-04 12:44:36</date><authorinitials>ClareCook</authorinitials></revision><revision><revnumber>45</revnumber><date>2013-03-08 10:28:25</date><authorinitials>localhost</authorinitials><revremark>converted to 1.6 markup</revremark></revision><revision><revnumber>44</revnumber><date>2012-05-16 14:15:59</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>43</revnumber><date>2012-05-16 14:00:55</date><authorinitials>JasonTaylor</authorinitials></revision><revision><revnumber>42</revnumber><date>2012-05-16 13:56:57</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>41</revnumber><date>2012-05-10 14:22:37</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>40</revnumber><date>2012-05-01 10:25:32</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>39</revnumber><date>2012-04-30 11:25:06</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>38</revnumber><date>2012-04-26 13:59:29</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>37</revnumber><date>2012-04-16 16:46:54</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>36</revnumber><date>2012-04-13 12:59:31</date><authorinitials>JasonTaylor</authorinitials></revision><revision><revnumber>35</revnumber><date>2012-04-13 12:52:41</date><authorinitials>JasonTaylor</authorinitials></revision><revision><revnumber>34</revnumber><date>2012-04-13 12:37:43</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>33</revnumber><date>2012-04-10 14:27:13</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>32</revnumber><date>2012-03-27 11:02:24</date><authorinitials>DennisNorris</authorinitials></revision><revision><revnumber>31</revnumber><date>2012-03-22 18:13:01</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>30</revnumber><date>2012-03-22 17:44:35</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>29</revnumber><date>2012-03-22 14:44:17</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>28</revnumber><date>2012-03-22 12:58:48</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>27</revnumber><date>2012-03-22 12:57:42</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>26</revnumber><date>2012-03-22 12:56:47</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>25</revnumber><date>2012-03-22 12:55:46</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>24</revnumber><date>2012-03-22 12:53:02</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>23</revnumber><date>2012-03-22 12:52:13</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>22</revnumber><date>2012-03-22 12:51:49</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>21</revnumber><date>2012-03-22 12:51:07</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>20</revnumber><date>2012-03-22 12:47:47</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>19</revnumber><date>2012-03-22 12:45:15</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>18</revnumber><date>2012-03-22 12:40:36</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>17</revnumber><date>2012-03-22 12:37:48</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>16</revnumber><date>2012-03-22 12:36:59</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>15</revnumber><date>2012-03-22 12:32:14</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>14</revnumber><date>2012-03-22 12:31:57</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>13</revnumber><date>2012-03-22 12:31:03</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>12</revnumber><date>2012-03-22 11:01:08</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>11</revnumber><date>2012-03-22 11:00:43</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>10</revnumber><date>2012-03-22 10:59:29</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>9</revnumber><date>2012-03-21 18:58:50</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>8</revnumber><date>2012-03-21 18:58:22</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>7</revnumber><date>2012-03-21 18:57:35</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>6</revnumber><date>2012-03-21 18:56:56</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>5</revnumber><date>2012-03-21 18:55:52</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>4</revnumber><date>2012-03-21 18:54:55</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>3</revnumber><date>2012-03-21 18:53:14</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>2</revnumber><date>2012-03-21 18:52:01</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>1</revnumber><date>2012-03-21 18:31:08</date><authorinitials>YaaraErez</authorinitials></revision></revhistory></articleinfo><section><title>Your Survival Guide to Unix at the CBSU</title><para>What you see below probably seems like a list of arbitrary incantations and may put you off ever going near a unix command line. However, you'll soon find that simple combinations of unix commands (possibly written as a shell script) can do things instantly that would take hours of pointing and clicking on a Mac or PC. </para><section><title>Commands for Navigation, File Manipulation etc.</title><informaltable><tgroup cols="3"><colspec colname="col_0"/><colspec colname="col_1"/><colspec colname="col_2"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para><emphasis role="strong">Function</emphasis> </para></entry><entry colsep="1" rowsep="1"><para><emphasis role="strong">Command</emphasis> </para></entry><entry colsep="1" rowsep="1"><para><emphasis role="strong">Examples</emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Show contents of current directory </para></entry><entry colsep="1" rowsep="1"><para><emphasis>ls</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>* details: <emphasis>ls –l</emphasis> </para><para> * hidden files: <emphasis>ls –a</emphasis> </para><para> * output to file: <emphasis>ls &gt; file.txt</emphasis> </para><para> wild cards: <emphasis>ls *.txt</emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Change directory </para></entry><entry colsep="1" rowsep="1"><para><emphasis>cd &lt;newdir&gt;</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>* <emphasis>cd /home/myname/mydatadir</emphasis> </para><para> * one up: <emphasis>cd ..</emphasis> (e.g. <emphasis>cd ../batchfiles</emphasis>) </para><para> * to home directory: <emphasis>cd ~</emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Make directory </para></entry><entry colsep="1" rowsep="1"><para><emphasis>mkdir &lt;newdir&gt;</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>* mkdir ./tmp creates directory 'tmp' in current directory </para><para>* mkdir ../tmp creates directory 'tmp' one level above current directory </para><para>* mkdir /home/yourname/subdir/tmp creates 'tmp' in /home/yourname/subdir/ </para><para>* mkdir ~/tmp creates 'tmp' in your home directory (same as mkdir /home/yourname/tmp) </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Copy file/directory </para></entry><entry colsep="1" rowsep="1"><para><emphasis>cp &lt;old&gt; &lt;new&gt;</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>Copy directories: <emphasis>cp -r &lt;old&gt; &lt;new&gt;</emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Move file/directory </para></entry><entry colsep="1" rowsep="1"><para><emphasis>mv &lt;old&gt; &lt;new&gt;</emphasis> </para></entry><entry colsep="1" rowsep="1"/></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Delete file/directory </para></entry><entry colsep="1" rowsep="1"><para><emphasis>rm &lt;filename&gt;</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>delete directory: <emphasis>rm –r &lt;dirname&gt;</emphasis>, suppress warning prompt: <emphasis>rm -f &lt;filename&gt;</emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Create link between a new filename and an existing file </para></entry><entry colsep="1" rowsep="1"><para><emphasis>ln &lt;filename&gt; &lt;linkname&gt;</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>symbolic link: <emphasis>ln -s &lt;filename&gt; &lt;linkname&gt;</emphasis>, to see whether a file is &quot;real&quot; or a symbolic link, use <emphasis>ls -l</emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Find a file in directory structure </para></entry><entry colsep="1" rowsep="1"><para><emphasis>find</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>* find <emphasis>myfile.txt</emphasis> in current directory and below: <emphasis>find . -name myfile.txt</emphasis> </para><para> * wildcards: <emphasis>find . -name \*results\*.txt</emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Find letter string within text </para></entry><entry colsep="1" rowsep="1"><para><emphasis>grep</emphasis> </para></entry><entry colsep="1" rowsep="1"><para><emphasis>grep error logfile.txt</emphasis>, <emphasis>ps -ef | grep &lt;yourname&gt;</emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>See list of previous commands </para></entry><entry colsep="1" rowsep="1"><para><emphasis>history</emphasis> </para></entry><entry colsep="1" rowsep="1"/></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Execute command from history list </para></entry><entry colsep="1" rowsep="1"><para><emphasis>!&lt;x&gt;</emphasis>, where <emphasis>x</emphasis> is number in history list </para></entry><entry colsep="1" rowsep="1"><para>e.g. <emphasis>!112</emphasis> to get command 112 from <emphasis>history</emphasis> list </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Send output of a command to text file </para></entry><entry colsep="1" rowsep="1"><para><emphasis>&gt;</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>e.g. <emphasis>ls -l &gt; listoffiles.txt</emphasis>, <emphasis>&gt;&gt;</emphasis> appends instead of overwriting </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Send output of a command directly to another command (&quot;pipes&quot;) </para></entry><entry colsep="1" rowsep="1"><para><emphasis>|</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>e.g. <emphasis> ls -l | grep myfile.txt </emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Send output of a command to text file AND standard output (screen) </para></entry><entry colsep="1" rowsep="1"><para><emphasis>tee</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>e.g. <emphasis>ls -l | tee listoffiles.txt</emphasis>, <emphasis>tee -a</emphasis> appends instead of overwriting </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Run progress in background (keep command prompt) </para></entry><entry colsep="1" rowsep="1"><para><emphasis>&amp;</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>e.g. <emphasis>matlab &amp;</emphasis>, <emphasis>runmybatch.sh &amp;</emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Changing access permissions </para></entry><entry colsep="1" rowsep="1"><para><emphasis>chmod</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>e.g. <emphasis>chmod 755 &lt;myfile&gt;</emphasis> or <emphasis>chmod go-w &lt;myfile&gt;</emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Changing group of a file </para></entry><entry colsep="1" rowsep="1"><para><emphasis>chgrp</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>e.g. <emphasis>chgrp imaging &lt;myfile&gt;</emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Create shortcut for command </para></entry><entry colsep="1" rowsep="1"><para><emphasis>alias</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>e.g. <emphasis>alias cd_batch &quot;cd &lt;mybatchdir&gt;&quot;</emphasis>, <emphasis>alias h history</emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Convert text files from DOS to Unix </para></entry><entry colsep="1" rowsep="1"><para><emphasis>dos2unix &lt;filename&gt;</emphasis> </para></entry><entry colsep="1" rowsep="1"/></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Edit files </para></entry><entry colsep="1" rowsep="1"><para><emphasis>nedit</emphasis>, <emphasis>emacs</emphasis>, <emphasis>vi</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>e.g. type <emphasis>nedit &amp;</emphasis> to keep command prompt </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Help on linux commands </para></entry><entry colsep="1" rowsep="1"><para><emphasis>man &lt;yourcommand&gt;</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>turn page using space bar, quit typing <emphasis>q</emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Short description of commands </para></entry><entry colsep="1" rowsep="1"><para><emphasis>whatis &lt;yourcommand&gt;</emphasis> </para></entry><entry colsep="1" rowsep="1"/></row></tbody></tgroup></informaltable></section></section><section><title>System-Related Commands</title><informaltable><tgroup cols="3"><colspec colname="col_0"/><colspec colname="col_1"/><colspec colname="col_2"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para>CBU Cluster Utility Functions </para></entry><entry colsep="1" rowsep="1"><para><emphasis>e.g. login_load, freenodes, showallmatlab</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>see <ulink url="http://intranet.mrc-cbu.cam.ac.uk/computing/cluster-utility/">CBU intranet</ulink> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Disk usage information </para></entry><entry colsep="1" rowsep="1"><para><emphasis>du</emphasis> </para></entry><entry colsep="1" rowsep="1"><para><emphasis>estimate space usage of directories and files, e.g. du –sh /imaging/xy01/experiment1</emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Change linux box </para></entry><entry colsep="1" rowsep="1"><para><emphasis>ssh &lt;machine&gt;</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>e.g. <emphasis>ssh l42</emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Show your jobs/processes in current session </para></entry><entry colsep="1" rowsep="1"><para>jobs </para></entry><entry colsep="1" rowsep="1"/></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Show current processes </para></entry><entry colsep="1" rowsep="1"><para><emphasis>ps</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>more details: <emphasis>ps -ef</emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Kill a process </para></entry><entry colsep="1" rowsep="1"><para><emphasis>kill</emphasis> </para></entry><entry colsep="1" rowsep="1"><para><emphasis>kill &lt;processID&gt;</emphasis>, where <emphasis>&lt;processID&gt;</emphasis> is from <emphasis>ps</emphasis> output </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Show most CPU-intensive tasks on current processor </para></entry><entry colsep="1" rowsep="1"><para><emphasis>top</emphasis> </para></entry><entry colsep="1" rowsep="1"/></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Checking where an executable file is located </para></entry><entry colsep="1" rowsep="1"><para><emphasis>which &lt;filename&gt;</emphasis> </para></entry><entry colsep="1" rowsep="1"/></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Show name of current linux box </para></entry><entry colsep="1" rowsep="1"><para><emphasis>hostname</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>ip address: <emphasis>hostname -i</emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Show features of current linux box </para></entry><entry colsep="1" rowsep="1"><para><emphasis>uname</emphasis> </para></entry><entry colsep="1" rowsep="1"><para>more details: <emphasis>uname -a</emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Check your user name </para></entry><entry colsep="1" rowsep="1"><para><emphasis>whoami</emphasis> </para></entry><entry colsep="1" rowsep="1"/></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Get time or date </para></entry><entry colsep="1" rowsep="1"><para><emphasis>time</emphasis>, <emphasis>date</emphasis> </para></entry><entry colsep="1" rowsep="1"/></row></tbody></tgroup></informaltable><section><title>Useful Tricks</title><informaltable><tgroup cols="1"><colspec colname="col_0"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para>Use cursor keys up/down to get previous commands </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Copy/paste: mark text with left mouse button, click to destination, click middle mouse button </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Auto-complete commands: start typing, then “Tab” to complete to next unique possibility </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Type the beginning of a previously used command, then simultaneously press <emphasis>Esc p</emphasis> to autocomplete to last used command with same beginning </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Move cursor to beginning <emphasis>Ctrl+a</emphasis> or end <emphasis>Ctrl+e</emphasis> of command line </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Run linux commands from within matlab using <emphasis>! &lt;command&gt;</emphasis> (e.g. <emphasis>! hostname</emphasis>) or <emphasis>[s,r] = unix(&lt;command&gt;)</emphasis> (e.g., <emphasis>[s,r] = unix('hostname')</emphasis>), where <emphasis>s</emphasis> returns the status (0=pass, nonzero=fail) and <emphasis>r</emphasis> is the result (e.g., 'l41'). </para></entry></row></tbody></tgroup></informaltable></section><section><title>General</title><informaltable><tgroup cols="1"><colspec colname="col_0"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para>Intro to Unix: <ulink url="http://www.ee.surrey.ac.uk/Teaching/Unix/"/> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>More <ulink url="http://wiki.mrc-cbu.cam.ac.uk/meg/Beginners#">computing-related intros</ulink> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Primer on <ulink url="http://wiki.mrc-cbu.cam.ac.uk/meg/AnalyzingData/Primer_ShellScripting#">shell scripting</ulink> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>VNC (<ulink url="http://wiki.mrc-cbu.cam.ac.uk/imaging/UsingVNC#">UsingVNC</ulink>): start Putty, <emphasis>vncserver –geometry 1280x1024 –name &lt;somename&gt;, for OpenGL graphics: </emphasis>vncserver.glx -geometry 1280x1024 -name &lt;somename&gt;<emphasis> </emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Access home space: Windows \\home\username; Linux /home/username </para></entry></row></tbody></tgroup></informaltable></section></section></article>