1.1 Listing files and directories ls (list)
When you login to your account, your current directory is your home directory and it has the same name as your login name, for example, model6, and all your personal files and sub directories are saved under your home directory.To find out what is in your home directory, type
% ls (short for list)The ls command lists the contents of your current working directory.There could be no files visible in your home directory, in which case, the UNIX prompt will be returned. Alternatively, there may already be some files inserted by the System Administrator when your account was created.
ls does not, in fact, lists all the files in your home directory, but only those ones whose name does not begin with a dot (.) Files beginning with a dot (.) are known as hidden files and usually contain important program configuration information. They are hidden because you should not change them unless you are very familiar with UNIX!!!
To list all files in your home directory including those whose names begin with a dot, type
% ls -als is an example of a command which can take options: -a is an example of an option. The options change the behavior of the command. There are online manual pages that tell you which options a particular command can take, and how each option modifies the behavior of the command. (See later in this tutorial)
1.2 Making Directories
mkdir (make directory)
We will now make a sub directory in your home directory to hold the files you will be creating and using in the course of this tutorial. To make a sub directory called pdb in your current working directory type% mkdir pdbTo see the directory you have just created, type% ls
1.3 Changing to a different directory cd (change directory)
The command cd <directory> means "change the current directory to a new 'directory'. The current directory may be thought of as the directory you are in, i.e. your current position in the file system tree.To change to the directory you have just made, type
% cd classType ls to see the contents (which should be empty)Make another directory inside the pdb directory.
Exercise
1.4 The directories Still in the class directory, type% ls -aAs you can see, in the class directory (and in all other directories), there are two special directories called "." and ".."In UNIX, "." means the current directory, so typing
% cd . (NOTE: there is a space between cd and the dot)means stay where you are (the class directory).
This may not seem very useful at first, but using "." as the name of the current directory will save a lot of typing, as we shall see later in the tutorial.
".." means the parent of the current directory, so typing
% cd ..will take you one directory up the hierarchy (back to your home directory). Try it.Note: typing cd with no argument always returns you to your home directory. This is very useful if you are lost in the file system.
1.5 Path names pwd (print working directory)
Path names enable you to work out where you are in relation to the whole file system. For example, to find out the absolute path name of your home directory, type cd to go to your home directory and then type% pwdThe full path name will look something like this -/usr/people/model6/classwhich means that model6 (your home directory) is in the directory people (the group directory), which is located under directory named usr and usr is directly under the root directory /.
Exercise 1b
Use the commands ls, pwd and cd to explore the file system.(Remember, if you get lost, type cd by itself to return to your home directory)
1.6 More about home directories and path names Understanding path names
First type cd .. to get out of your home directory, then type% ls model6to list the contents of your home directory.
Now type
% ls classYou will get a message like this -class: No such file or directoryThe reason is, class is not in your current working directory. To use a command on a file (or directory) not in the current working directory (the directory you are currently in), you must either cd to the correct directory, or specify its full path name. To list the contents of your class directory, you must type% ls model6/backups
if your current directory is people~ (your home directory)
Home directories can also be referred to by the tilde ~ character. It can be used to specify paths starting at your home directory. So typing% ls ~/classwill list the contents of your class directory, no matter where you currently are in the file system.What do you think
% ls ~would list?What do you think
% ls ~/..would list?
Summary
ls list files and directories ls -a list all files and directories mkdir make a directory cd directory change to named directory cd change to home directory cd ~ change to home directory cd .. change to parent directory pwd display the path of the current directory
| 1.7 Copying Files |
cp (copy)
cp file1 file2 is the command which makes a copy of file1 in the current working directory and calls it file2What we are going to do now, is to take a file stored in an open access area of the file system, and use the cp command to copy it to your pdb directory.
First, cd to your pdb directory.
% cd pdbThen at the UNIX prompt, type,% cp ~/1A3Y.pdb .(Note: Don't forget the dot "." at the end. Remember, in UNIX, the dot means the current directory.)The above command means copy the file 1BVQ.pdb to the current directory, keeping the name the same.
Exercise
Create a backup of your 1A3Y.pdb file by copying it to a file called 1A3Y.pdb.bck
1.8 Moving files mv (move)
mv file1 file2 moves (or renames) file1 to file2To move a file from one place to another, use the mv command. This has the effect of moving rather than copying the file, so you end up with only one file rather than two.
It can also be used to rename a file, by "moving" the file to the same directory, but giving it a different name.
We are now going to move the file 1A3Y.pdb.bck to your backup directory (create a backups directory first
under your pdb directory.First, change directories to your pdb directory (can you remember how?). Then, inside the pdb directory, type
% mv 1A3Y.pdb.bck backups/.Type ls and ls backups to see if the file has been moved successfully.
1.9 Removing files and directories rm (remove, delete), rmdir (remove, delete directory)
To delete (remove) a file, use the rm command. Here is an example of deleting a file.Inside your pdb directory, type
% cp 1A3Y.pdb tempfile.txtYou can use the rmdir command to remove a directory (make sure it is empty first). Try to remove the backups directory. You will not be able to since UNIX will not let you remove a non empty directory.
% ls (to check if it has created the file)
% rm tempfile.txt
% ls (to check if it has deleted the file)A powerful addition for rm
% rm -rf *
will remove everything starting from your current directory and below if you are the owner of the everything
in those directories. Use it very carefully, once it was deleted there is no way you can get them back easily.Exercise
Create a directory called tempstuff using mkdir , then remove it using the rmdir command.
1.10 Displaying the contents of a file on the screen clear (clear screen)
Before you start the next section, you may like to clear the terminal window of the previous commands so the output of the following commands can be clearly understood.At the prompt, type
% clearThis will clear all text and leave you with the % prompt at the top of the window.
cat (concatenate)
The command cat can be used to display the contents of a file on the screen. Type:% cat 1A3Y.pdbAs you can see, the file is longer than than the size of the window, so it scrolls past making it unreadable.
more
The command more writes the contents of a file onto the screen a page at a time. Type% more 1A3Y.pdbPress the space-bar if you want to see another page, type q if you want to quit reading. As you can see, more is used in preference to cat for long files.
head
The head command writes the first ten lines of a file to the screen.First clear the screen then type
% head 1A3Y.pdbThen type% head -5 1A3Y.pdbWhat difference did the -5 do to the head command?
tail
The tail command writes the last ten lines of a file to the screen.Clear the screen and type
% tail 1A3Y.pdbHow can you view the last 15 lines of the file?
1.11 Searching the contents of a file Simple searching using more
Using more, you can search though a text file for a keyword (pattern). For example, to search through 1A3Y.pdb for the word END, type% more 1A3Y.pdbthen, still in more (i.e. don't press q to quit), type a slash followed by the word to search/ENDAs you can see, more finds and highlights the keyword. Type n to search for the next occurrence of the word.
grep (don't ask why it is called grep)
grep is one of many standard UNIX utilities. It searches files for specified words or patterns. First clear the screen, then type% grep 'CA CYS' 1A3Y.pdbAs you can see, grep has printed out each line containing CA CYS. So you can use it to get total number of
CYS residues in this protein.Try typing
% grep 'CA Cys' 1A3Y.pdbThe grep command is "case sensitive"; it distinguishes between upper case and lower case lettersTo ignore upper/lower case distinctions, use the -i option, i.e. type
% grep -i 'ca cys' 1A3Y.pdbSome of the other options of grep are:
-v display those lines that do NOT match
-n precede each matching line with the line number
-c print only the total count of matched linesTry some of them and see the different results. Don't forget, you can use more than one option at a time, for example, the number of lines without the words CYS or cys is
% grep -ivc cys 1A3Y.pdbwc (word count)
A useful unix utility is the wc command. To do a word count on 1BVQ.pdb, type% wc -w 1A3Y.pdbTo find out how many lines the file has, type
it will print the number of bytes, words, and lines 1A3Y.pdb
% wc -l 1A3Y.pdb
Summary
cp file1 file2 copy file1 and call it file2 mv file1 file2 move or rename file1 to file2 rm file remove a file rmdir directory remove a directory cat file display a file more file display a file a page at a time head file display the first few lines of a file tail file display the last few lines of a file grep 'keyword' file search a file for keywords wc file count number of lines/words/characters in file
| Text Editors |
There are three basic editors you can use for editing the text file:
vi editor (screen editor, a default editor on all UNIX machines. A little bit hard to learn but you should master it)
vi filename
[Enter]
jot editor (only available on IRIX. A very simple and easy to use, GUI based editor. You should use it here)
jot filename
[Enter]
nedit editor (Really good multi-function GUI based text editor. Programmers love it and is available on our SGIs)
nedit filename [Enter]