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 |
Examples |
Show contents of current directory |
ls |
* details: ls –l |
Change directory |
cd <newdir> |
* cd /home/myname/mydatadir |
Make directory |
mkdir <newdir> |
* mkdir ./tmp creates directory 'tmp' in current directory |
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 |
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> |
|