2769
Comment:
|
5881
|
Deletions are marked like this. | Additions are marked like this. |
Line 2: | Line 2: |
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. | |
Line 3: | Line 4: |
== Commands == || '''Function''' || '''Command''' || '''Options''' || || Show contents of current directory || ''ls'' || details: ''ls –l'', hidden files: ''ls –a'', output to file: ''ls > file.txt'', wild cards: ''ls *.txt'' || || Change directory || ''cd <newdir>'' || e.g. ''cd /home/myname/mydatadir'', one up: ''cd ..'' (e.g. ''cd ../batchfiles'', to home directory: ''cd ~'') || ||Make directory || ''mkdir <newdir>'' || || || Copy file/directory || ''cp <old> <new>'' || || || Move file || ''mv <old> <new>'' || || || Delete file || ''rm <filename>'' || delete directory: ''rm –r <dirname>'' || || Search for files in directory structures || ''find'' || || || Find letter string within text || grep || ''grep error logfile.txt'', ''grep <yourname> | ps -ef'' || || See list of previous commands || ''history'' || || || Execute command from history list || ''!<x>'', where ''x'' is number in history list || e.g. '''!112'' || || Changing access permissions || ''chmod'' || e.g. ''chmod 755 <myfile>'' || || Show load of linux boxes || ''showload'' || || || Change linux box || ''ssh <machine>'' || e.g. ''ssh l42'' || || Show current processes || ''ps'' || ''ps -ef'' || || Show most CPU-intensive tasks on current processor || ''top'' || || || Checking where an executable file is located || ''which <filename>'' || || || Show features of current linux box || ''uname –a'' || || || Check your user name || ''whoami'' || || || Convert text files from DOS to Unix || ''dos2unix <filename>'' || || || Edit files || ''nedit'', ''emacs'', ''vi'' || || || Help on linux commands || ''man yourcommand'' (quit typing ''q'') || || |
== Commands for Navigation, File Manipulation etc. == ||'''Function''' ||'''Command''' ||'''Options''' || ||Show contents of current directory ||''ls'' ||details: ''ls –l'', hidden files: ''ls –a'', output to file: ''ls > file.txt'', wild cards: ''ls *.txt'' || ||Change directory ||''cd <newdir>'' ||e.g. ''cd /home/myname/mydatadir'', one up: ''cd ..'' (e.g. ''cd ../batchfiles''), to home directory: ''cd ~'' || ||Make directory ||''mkdir <newdir>'' ||mkdir ./tmp creates directory 'tmp' in current directory mkdir ../tmp creates directory 'tmp' one level above current directory mkdir /home/yourname/subdir/tmp creates 'tmp' in /home/yourname/subdir/ mkdir ~/tmp creates 'tmp' in your home directory (same as mkdir /home/yourname/tmp) || ||Copy file/directory ||''cp <old> <new>'' ||Copy directories: ''cp -r <old> <new>'' || ||Move file/directory ||''mv <old> <new>'' || || ||Delete file/directory ||''rm <filename>'' ||delete directory: ''rm –r <dirname>'', suppress warning prompt: ''rm -f <filename>'' || ||Create link between a new filename and an existing file ||''ln <filename> <linkname>'' ||symbolic link: ''ln -s <filename> <linkname>'', to see whether a file is "real" or a symbolic link, use ''ls -l'' || ||Find a file in directory structure ||''find'' ||find ''myfile.txt'' in current directory and below: ''find . -name myfile.txt'', wildcards: ''find . -name \*results\*.txt'' || ||Find letter string within text ||''grep'' ||''grep error logfile.txt'', ''ps -ef | grep <yourname>'' || ||See list of previous commands ||''history'' || || ||Execute command from history list ||''!<x>'', where ''x'' is number in history list ||e.g. ''!112'' to get command 112 from ''history'' list || ||Send output of a command to text file ||''>'' ||e.g. ''ls -l > listoffiles.txt'', ''>>'' appends instead of overwriting || ||Send output of a command directly to another command ("pipes") ||''|'' ||e.g. '' ls -l | grep myfile.txt '' || ||Send output of a command to text file AND standard output (screen) ||''tee'' ||e.g. ''ls -l | tee listoffiles.txt'', ''tee -a'' appends instead of overwriting || ||Run progress in background (keep command prompt) ||''&'' ||e.g. ''matlab &'', ''runmybatch.sh &'' || ||Changing access permissions ||''chmod'' ||e.g. ''chmod 755 <myfile>'' or ''chmod go-w <myfile>'' || ||Changing group of a file ||''chgrp'' ||e.g. ''chgrp imaging <myfile>'' || ||Create shortcut for command ||''alias'' ||e.g. ''alias cd_batch "cd <mybatchdir>"'', ''alias h history'' || ||Convert text files from DOS to Unix ||''dos2unix <filename>'' || || ||Edit files ||''nedit'', ''emacs'', ''vi'' ||e.g. type ''nedit &'' to keep command prompt || ||Help on linux commands ||''man <yourcommand>'' ||turn page using space bar, quit typing ''q'' || ||Short description of commands ||''whatis <yourcommand>'' || || = System-Related Commands = ||CBU Cluster Utility Functions ||''e.g. login_load, freenodes, showallmatlab'' ||see [[http://intranet.mrc-cbu.cam.ac.uk/computing/cluster-utility/|CBU intranet]] || ||Disk usage information ||''du'' ||''estimate space usage of directories and files, e.g. du –sh /imaging/xy01/experiment1'' || ||Change linux box ||''ssh <machine>'' ||e.g. ''ssh l42'' || ||Show your jobs/processes in current session ||jobs || || ||Show current processes ||''ps'' ||more details: ''ps -ef'' || ||Kill a process ||''kill'' ||''kill <processID>'', where ''<processID>'' is from ''ps'' output || ||Show most CPU-intensive tasks on current processor ||''top'' || || ||Checking where an executable file is located ||''which <filename>'' || || ||Show name of current linux box ||''hostname'' ||ip address: ''hostname -i'' || ||Show features of current linux box ||''uname'' ||more details: ''uname -a'' || ||Check your user name ||''whoami'' || || ||Get time or date ||''time'', ''date'' || || |
Line 28: | Line 46: |
|| Use cursor keys up/down to get previous commands || || Copy/paste: mark text with left mouse button, click to destination, click middle mouse button || || Auto-complete commands: start typing, then “Tab” to complete to next unique possibility || |
||Use cursor keys up/down to get previous commands || ||Copy/paste: mark text with left mouse button, click to destination, click middle mouse button || ||Auto-complete commands: start typing, then “Tab” to complete to next unique possibility || ||Type the beginning of a previously used command, then simultaneously press ''Esc p'' to autocomplete to last used command with same beginning || ||Move cursor to beginning ''Ctrl+a'' or end ''Ctrl+e'' of command line || ||Run linux commands from within matlab using ''! <command>'' (e.g. ''! hostname'') or ''[s,r] = unix(<command>)'' (e.g., ''[s,r] = unix('hostname')''), where ''s'' returns the status (0=pass, nonzero=fail) and ''r'' is the result (e.g., 'l41'). || |
Line 34: | Line 55: |
|| VNC (http://imaging.mrc-cbu.cam.ac.uk/imaging/UsingVNC): Putty, ''vncserver –geometry 1280x1024 –name <somename>, for OpenGL graphics: ''vncserver.glx -geometry 1280x1024 -name <somename>'' || || Access home space: Windows \\home\username; Linux /home/username || || Access imaging space: Windows \\samfs-lh\imaging; Linux /imaging/username || || 32-bit machines: l21, l24-31, l33-l36, l37-l42 64-bit machines: l43-l63 OpenGL machines: l37-l42 || || Computing on Intranet: http://intranet.mrc-cbu.cam.ac.uk/computing/ || || Intro to Unix: http://www.ee.surrey.ac.uk/Teaching/Unix/ || || Overview of CBU computing: http://imaging.mrc-cbu.cam.ac.uk/meg/Beginners/MatlabIntroCBU?action=AttachFile&do=get&target=RussellComputing.pdf || |
||Overview of CBU computing: http://imaging.mrc-cbu.cam.ac.uk/meg/Beginners/MatlabIntroCBU?action=AttachFile&do=get&target=RussellComputing.pdf || ||Computing on Intranet: http://intranet.mrc-cbu.cam.ac.uk/computing/ || ||Intro to Unix: http://www.ee.surrey.ac.uk/Teaching/Unix/ || ||More [[CbuMeg:Beginners|computing-related intros]] || ||Primer on [[CbuMeg:AnalyzingData/Primer_ShellScripting|shell scripting]] || ||VNC (CbuImaging:UsingVNC): start Putty, ''vncserver –geometry 1280x1024 –name <somename>, for OpenGL graphics: ''vncserver.glx -geometry 1280x1024 -name <somename>'' '' || ||Access home space: Windows \\home\username; Linux /home/username || ||Access imaging space: Windows \\samfs-lh\imaging; Linux /imaging/username || ||32-bit machines: l21, l24-31, l33-l36, l37-l42; 64-bit machines: l43-l63; OpenGL machines: l37-l42 || |
Your Survival Guide to Unix at the CBSU
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.
Commands for Navigation, File Manipulation etc.
Function |
Command |
Options |
Show contents of current directory |
ls |
details: ls –l, hidden files: ls –a, output to file: ls > file.txt, wild cards: ls *.txt |
Change directory |
cd <newdir> |
e.g. cd /home/myname/mydatadir, one up: cd .. (e.g. cd ../batchfiles), to home directory: cd ~ |
Make directory |
mkdir <newdir> |
mkdir ./tmp creates directory 'tmp' in current directory mkdir ../tmp creates directory 'tmp' one level above current directory mkdir /home/yourname/subdir/tmp creates 'tmp' in /home/yourname/subdir/ mkdir ~/tmp creates 'tmp' in your home directory (same as mkdir /home/yourname/tmp) |
Copy file/directory |
cp <old> <new> |
Copy directories: cp -r <old> <new> |
Move file/directory |
mv <old> <new> |
|
Delete file/directory |
rm <filename> |
delete directory: rm –r <dirname>, suppress warning prompt: rm -f <filename> |
Create link between a new filename and an existing file |
ln <filename> <linkname> |
symbolic link: ln -s <filename> <linkname>, to see whether a file is "real" or a symbolic link, use ls -l |
Find a file in directory structure |
find |
find myfile.txt in current directory and below: find . -name myfile.txt, wildcards: find . -name \*results\*.txt |
Find letter string within text |
grep |
grep error logfile.txt, ps -ef | grep <yourname> |
See list of previous commands |
history |
|
Execute command from history list |
!<x>, where x is number in history list |
e.g. !112 to get command 112 from history list |
Send output of a command to text file |
> |
e.g. ls -l > listoffiles.txt, >> appends instead of overwriting |
Send output of a command directly to another command ("pipes") |
| |
e.g. ls -l | grep myfile.txt |
Send output of a command to text file AND standard output (screen) |
tee |
e.g. ls -l | tee listoffiles.txt, tee -a appends instead of overwriting |
Run progress in background (keep command prompt) |
& |
e.g. matlab &, runmybatch.sh & |
Changing access permissions |
chmod |
e.g. chmod 755 <myfile> or chmod go-w <myfile> |
Changing group of a file |
chgrp |
e.g. chgrp imaging <myfile> |
Create shortcut for command |
alias |
e.g. alias cd_batch "cd <mybatchdir>", alias h history |
Convert text files from DOS to Unix |
dos2unix <filename> |
|
Edit files |
nedit, emacs, vi |
e.g. type nedit & to keep command prompt |
Help on linux commands |
man <yourcommand> |
turn page using space bar, quit typing q |
Short description of commands |
whatis <yourcommand> |
|
System-Related Commands
CBU Cluster Utility Functions |
e.g. login_load, freenodes, showallmatlab |
see CBU intranet |
Disk usage information |
du |
estimate space usage of directories and files, e.g. du –sh /imaging/xy01/experiment1 |
Change linux box |
ssh <machine> |
e.g. ssh l42 |
Show your jobs/processes in current session |
jobs |
|
Show current processes |
ps |
more details: ps -ef |
Kill a process |
kill |
kill <processID>, where <processID> is from ps output |
Show most CPU-intensive tasks on current processor |
top |
|
Checking where an executable file is located |
which <filename> |
|
Show name of current linux box |
hostname |
ip address: hostname -i |
Show features of current linux box |
uname |
more details: uname -a |
Check your user name |
whoami |
|
Get time or date |
time, date |
|
Useful Tricks
Use cursor keys up/down to get previous commands |
Copy/paste: mark text with left mouse button, click to destination, click middle mouse button |
Auto-complete commands: start typing, then “Tab” to complete to next unique possibility |
Type the beginning of a previously used command, then simultaneously press Esc p to autocomplete to last used command with same beginning |
Move cursor to beginning Ctrl+a or end Ctrl+e of command line |
Run linux commands from within matlab using ! <command> (e.g. ! hostname) or [s,r] = unix(<command>) (e.g., [s,r] = unix('hostname')), where s returns the status (0=pass, nonzero=fail) and r is the result (e.g., 'l41'). |
General
Overview of CBU computing: http://imaging.mrc-cbu.cam.ac.uk/meg/Beginners/MatlabIntroCBU?action=AttachFile&do=get&target=RussellComputing.pdf |
Computing on Intranet: http://intranet.mrc-cbu.cam.ac.uk/computing/ |
Intro to Unix: http://www.ee.surrey.ac.uk/Teaching/Unix/ |
Primer on shell scripting |
VNC (UsingVNC): start Putty, vncserver –geometry 1280x1024 –name <somename>, for OpenGL graphics: vncserver.glx -geometry 1280x1024 -name <somename> |
Access home space: Windows \\home\username; Linux /home/username |
Access imaging space: Windows \\samfs-lh\imaging; Linux /imaging/username |
32-bit machines: l21, l24-31, l33-l36, l37-l42; 64-bit machines: l43-l63; OpenGL machines: l37-l42 |