Unix Tutorials For Beginners

23rd Friday Nov 2001

by M. Madan babu, I Yr PhD student with Dr. Sarah Teichmann
Structural Studies Division
MRC-Laboratory of Molecular Biology
http://www.mrc-lmb.cam.ac.uk/genomes/madanm/utut.htm

1. pwd - present working directory
This command will tell you the present directory in which you are situated.
eg: %>  pwd
2. ls - used to list files
This is a command which is analogous to the 'dir' command in dos. With this command,
you can display the list fo files which you have in a particular directory. 
There are various options associated with the ls command which you can invoke by 
jusy typing 'ls -option'
eg: %> ls -al
3. mkdir - used to create a new directory
This command is used to create a new directory. A directory is analogous to a 
'folder' in windows.
eg: %> mkdir mrc-lmb

4. cd - used to change directory
This command is used to change directory. This is analogous to clicking a folder 
icon in windows.

Points to remember:
Each new directory created will automaticaly have two files
the '.' and the '..'
The '.' file is the one which points to the current directory
The '..' file is the one which points to the previous directory

Assume that this is a  directory structure:

-->root 
        --> mrc-lmb
                 --> users
                         --> madan     
                                -->rasmol 
                                -->insight
                         --> christine
                         --> sarah
                         --> cyrus
                 --> guest
                         --> CIMRusers
                         --> HGMPusers

when you login as 'madan'. You will automaticall be taken to the folder called 
'madan' in the above directory structure.

to change the current directory to 'sarah', you will have to type the following:
eg: %> cd ../sarah

what this does is the following:
     .. points to the immediate previous directory (which is users)
     /sarah changes the directory to 'sarah' 
    
to change the current directory to CIMRusers, you will have to type the following:
eg: %> cd ../../guest/CIMRusers

the command to change from CIMRusers to rasmol will be the following:
eg: %> cd ../../users/madan/rasmol

Thus the whole thing is like tracing a path from one directory to another 
with a set of rules which is:
 1. to go to the previous directory use '..'
 2. to go to the sub-directory use '/'

5. echo - used to display something on the screen 
This is a command which allows users to put in information in to a particular
file in combination with the redirection symbol '>'. 
eg: %> echo 'MRC-LMB is a non-profit organization' > filename

Points to remember:
The standard output (which you see on the screen) can be captured in to a text file by this 
redirection process in to another file. The file to which
redirection is pointed will be automatically created if it does not exist.

There are two types of redirection:
a. Overwrite - This will overwrite an existing file - '>'
b. Append - This will add the information at the end of an existing file - '>>'

eg: %> type 'this will overwrite' > filename
eg: %> type 'this will append'  >> filename


6. type and cat - used to list the contents of a file
This is a command which allows the user to type out the contents of a text files. 
Please do not use type to list contents of a binary file
(binary files are executable files in linux/unix).
eg: %> type filename
eg: %> cat filename > filename2

7. cp - used to copy files
This command is used to copy files 
eg: %> cp filename1 filename2
eg: %> cp filename1 ./directory/filename2


8. mv - used to rename files
This command is used to rename files and to move files from on directory to another
eg: %> mv filename1 filename2
eg: %> mv filename1 ./directory/filename2


9. grep - global regular expression printer
This a very powerful command which searches for patterns in your text file.
eg: %> grep 'mrc' filename
this will list all lines which has 'mrc' in the file 'filename'
eg: %> grep -i 'mrc' filename
case insensitive pattern search
eg: %> grep -v 'mrc' filename
this will list all lines which does not match the pattern

Point to remember:
A pattern is a word, set of words which you are searching for

10. head - used to list the first 10 lines in a file
eg: %> head filename
eg: %> head -15 filename 
the last command will display the first 15 lines of the file


11. tail - used to list the last 10 lines in a file 
eg: %> tail filename
eg: %> tail -15 filename
the last command will display the last 15 lines of the file

12. du - used to get the amount of disk space used
The amount of harddisk space used is mentioned in terms of Kb. 1000 Kb forms 1 Mb
eg: %> du

13. rm - used to remove unwanted files
This command is analogous to 'delete' in dos and in windows. The only problem is 
that there is no 'recycle bin' which temporarily stores the file. so please be 
ABSOLUTELY  SURE BEFORE YOU DELETE A FILE!!. 
eg: %> rm filename
eg: %> rm -rf directory
the last command will remove all files in that particular directory and will 
also remove the directory.
14. find OR locate - finding for a file 
This command is used to find the directory in which a particular file you 
are looking for is located in. This is similar to the windows 'search' program.
eg: %> find . -name filename* -print
eg: %> locate madan*

Points to remember:
1. * match an arbitrary length
2. ? match a single character
3. [...] match any name in braces
4. [^..] match any name not in braces
5. ^pattern do not match pattern

eg: %> ls mrc*
will list files with names: mrc, mrc-lmb, mrcusers, mrc-dunn, etc
eg: %>ls mr?
will list files with names: mrc, mri, mr[any thing here which is of a 
single alphabet/number]]
eg: %>ls [Mm][Rr][Cc]
will list the files with names: Mrc, MRc, MRC, etc
15. passwd - change password
This command is used to change your present password. When you login and type passwd,
the old passwd will be asked and then the new passwd will be prompted for. Once you i
type the new password, you will be asked to reconfirm.