Basic Unix Commands and Web Tutorials | Print |
 

There are many sources of UNIX tutorials.
A few of these are:
http://www.ee.surrey.ac.uk/Teaching/Unix
http://www.math.utah.edu/lab/unix/unix-tutorial.html http://www.unixtools.com/tutorials.html

General command format:

        command   arg1   arg2  ...

OR

        command  -option  arg1  arg2 ...

Commands are grouped on basis of usage:

  1. Working with Directories.
  2. Working with files.
  3. Viewing File content.
  4. Manipulating Files.
  5. Printing.
  6. Important UNIX conventions.
  7. Miscellaneous.

Note:

The commands are red in color.
The options/information to be used/provided along with the commands are in blue, e.g cd mydirectory where cd is the command and mydirectory is the information provided by you, i.e. the directory you want to change to.


 

Working with Directories

 

Command: Description:
pwd Displays the name of your present working directory, i.e. the directory you are currently in.
cd Go to your home directory, i.e. the directory you start in when you login.
cd    ~ same as above
cd .. go to the parent of the directory you are in now [ move up by 1 directory ]
cd dirname change to directory named dirname
mkdir dirname creates a directory called dirname in the current directory
rmdir dirname delete (remove) empty directory dirname

Directory Notes

In UNIX pathnames, slashes (/) separate the directory and filenames
e.g. /home/mcb/myfile.txt  [ here home and mcb are directories and myfile.txt is a file ].


 Working with files

 

Command: Description:
ls lists the contents of the current directory
ls dirname lists the contents of directory called dirname
e.g ls /home/mcb
ls -l (or ll) shows a "long", detailed listing
ls -a lists ALL files, including those starting with "."



Viewing File content

 

Command: Description:
more filename displays the first screenfull of the file called filename
The rest of these are options to be used _within_  more i.e. after you type more filename
[ret] page down a line in the file. NOTE [ret] is pressing the Enter or Return key on your keyboard.
_spacebar_ shows the next screen worth of the file. NOTE _spacebar_  is pressing the spacebar on your keyboard
xx[ret] pages down xx lines, where xx is a number
/abc[ret] takes you to the next occurence of the text "abc"
G go to the end of the file
b page up one screen's worth in the file
xxb pages up xx lines, where xx is a number
q to exit more



 Manipulating Files

 

Command: Description:
mv file1 file2 moves (renames) file1 to file2
mv f1 dir/f1 moves file f1 from current directory to directory dir
cp file1 file2 makes a copy of file1 named file2
cp f1 dir/f1 makes a copy of file f1, called f1, in directory dir
rm filename deletes the file called filename.  Use this command carefully - there is no Undo!!

pico 

OR

nedit

puts you in an editor to create a new file

pico filename

OR

nedit filename

puts you in the editor to edit filename


 Printing

 

Command: Description:
lpr f1 print file named f1 to default printer
lpr -Plp f1 print file named f1 to printer named lp
lpq check the print queue for the default printer
lpr -Plp check the print queue for the printer named lp
lpstat -a check status of all available print queues

 


Important UNIX conventions

 

Command format Commands must be typed all on one line, with spaces between the command, options, and arguments.

Naming

Files

Filenames consist of alphanumeric characters, underscores, dashes, and periods.  DO NOT use spaces or other punctuation in filenames!

Case

Sensitivity

Commands and filename in UNIX are case sensitive!!
Filename Completion After typing a unique prefix of a filename, pressing the Tab key will cause the UNIX shell to complete the filename.
Command Editing The up arrow key will retrieve a previous command. This command may be edited using the left/right arrow keys and backspace. 
^Z In UNIX, this sends a process to run in the background. The process will still exist; you just won't see it. Type "fg" to bring it back so that you can exit properly. Don't exit with processes running in the background.

 


Miscellaneous

 

passwd type this to change your password
pine to read or send mail
man topic to see online help for topic
man -k topic to see a list of commands related to topic
^D type this to logout
^C this will _usually_ kill  [terminate] whatever you are in the middle of.

 

Some helpful UNIX command pipelines:

To check the number of files in a directory (wc –l is word count with lower case L option):
cd    directory
ls | wc  –l

To check the number of files in a set of directories, e.g. all Run* directories (do not type the ?s):
foreach  d  (Run*)
? ls  $d | wc  -l
? end

To search for a word in a file (e.g. Bluescript in Mask file, -i is case insensitive):
grep -i Bluescript  Maskfile

To count the number of sequences in a FASTA file:
grep  “>”  Myfile.fasta | wc -l

To count the number of queries in a BLAST report file:
grep  “Query=”  MyBLAST.bln | wc  -l