Вы находитесь на странице: 1из 28

Definitions

Typographical definitions
The following typographical conventions are used while typing unix commands:
1) Characters in bold face are commands to be typed as is!!.
2) Characters in italic face indicate arbitrary file or directory names.
3) Words inserted between square brackets [ ] indicate the keyboard keys to be pressed.
Example,
% ls any directory [Enter]
means "at the UNIX prompt %, type ls followed by the name of some directory, then press the key marked
Enter"
4) Don't forget to press the [Enter] key: a command you typed onto the computer screen will not be
executed without pressing this key.
Notice: UNIX is case sensitve, so LS is not the same as ls.
The same applies to filenames,
so sequence.txt, Sequence.txt and SEQUENCE.TXT are three different file
names. However, DOS and Windows do not make these distinctions.

How to Use Unix or Linux


A Little History
Unix is an operating system with quite a lot of history. Unix began in the early '70s when a small research
group at Bell labs wrote the first Unix kernel (the core of the operating system) and some tools. The tool set
of Unix was designed as set of small utilities - each of them designed to do a single task well - which would
all fit together to perform more complex tasks. Early in its life Unix was re-written in c (it had previously
been written in assembly language, as were most of the operating systems of the day). The fact that it was
written in c made Unix very portable. Throughout the '70s Unix became very popular. The code was shared
out to many Universities and other institutions, many of whom made their own fixes, improvements and
tools which made their way back into the operating system ``distribution''.
Eventually, AT&T and others figured out that Unix could be sold for big money. Companies began
implementing their own versions of Unix and keeping their own code secret. Unix began to ``fork'', or split
into many versions with varying degrees of incompatibility. By the mid-eighties the Unix community was a
disparate set of factions who found it difficult to agree on anything. Around the same time, the IBM PC was
becoming popular, gradually moving computing away from the large machines on which Unix ran.
Microsoft DOS, and later Windows took over as the dominant desktop operating system. As the PC became
more powerful, PCs running Windows began to compete in areas where Unix had been used. Eventually PCs
became powerful enough to think of using them as small servers, a use that Novell championed with it's

NetWare series of network operating systems for the PC, followed by Microsoft with the development of
Windows NT.
The original PCs were not really suitable for running a multi-tasking operating system like Unix. As they
became more powerful, apart from gaining enough power to run Windows, some people began to think they
might be able to run some form of Unix. One of those was George Tannenbaum, who coded a small version
of Unix called minix for the PC. One person who was interested in minix was a computing student in
Finland called Linus Torvalds. Linus became frustrated with some of the limitations of minix (many of
which stemmed from it's design philosophy of supporting the lowest common denominator) and the
licensing, which made it difficult to fix the parts of minix which he thought were broken. Linus decided to
code his own operating system based on Unix. The first release was in 1991, when he invited anyone and
everyone via the Internet to have a look through his code and help to develop it.
As it turned out, Linus was very good at fostering a community around Linux. He is credited with being
very congenial, willing to let others take or share credit for their work and fairly liberal in deciding which
additions should go back into Linux itself. These features, along with the rise of the Internet as a means of
communicating and sharing data were instrumental in building Linux into a very popular and strong
operating system. Linux was placed under the GNU General Public Licence (GPL), which is a copyright,
but stipulates that the code should always be made available with the program (and those derived from it). In
this way, there is a legal guarantee that the code hiding (and consequent forking) which happened to
Unix cannot happen to Linux.
To the user, Linux is almost indistinguishable from other Unices. The rise in popularity of Linux has also
helped raise the level of knowledge of Unix amongst millions of students around the world over the last
decade. There are now a great number of people working in computing who have Unix knowledge and
skills. There are also other free Unices which have benefited from all of this. The most famous are the
variants of BSD (Berkeley Systems Distribution) for the PC which have a reputation for quality. As I write
this Unix, whether on a PC, a workstation or a big server, is increasing again in popularity. 60% of all web
servers on the Internet use Apache (a free web server) running on Linux or Unix, up from a little over 50% a
couple of years ago. Around 25% of servers now run Linux, up from almost nothing a few years ago.
Amongst Internet service providers usage is even higher (44%) - since Linux comes with source code it can
be modified to run on custom rack-mountable hardware which is perfect for serving large numbers of
connections. Amongst Universities usage of Linux is also strong - many Universities still have large
amounts of Unix expertise and Linux fits in well. Also, Linux is extremely inter-operable with most other
systems, speaking most network protocols and able to use many different file-systems, making it perfect in
an environment with many computing platforms.

The rise of Linux brings us pretty much up to date. At the time of writing of this history, it is unclear
whether this will lead to any significant change on Microsoft's hold over the desktop market. One thing is
clear - there are some interesting times ahead.

1. File system
In Unix, the files are organized into a tree structure with a root named by the character '/'. The first few
levels of the tree look like this:

Your own files form a subtree of this trees structure. For example, in many systems the user files are
subdirectories of a directory named `home' or 'people' within `usr'; if we had users Jack and model6, for
example,
Jack's home directory would be /usr/people/jack (on IRIX), and all his files would be within that
subtree, and the analogous statement would hold for model6.
Suppose model6's directory looks like this:

2. File Types
There are four types of files in the Unix file system.
2.1 Ordinary Files
An ordinary file may contain text, a program, or other data. It can be either an ASCII file, with
each of its bytes being in the numerical range 0 to 127, i.e. in the 7-bit range, or a binary file, whose bytes
can be of all possible values 0 to 255, in the 8-bit range.

2.2 Directory Files


Suppose that in the directory x I have a, b and c, and that b is a directory, containing files u and v.
Then b can be viewed not only as a directory, containing further files, but also as a file itself. The file b
consists of information about the directory b; i.e. the file b has information stating that the directory b has
files u and v, how large they are, when they were last modified, etc.
2.3 Device Files
In Unix, physical devices (printers, terminals etc.) are represented as ``files.'' This seems odd at
first, but it really makes sense: This way, the same read() and write() functions used to read and write real
files can also be used to read from and write to these devices.
2.4 Link Files

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 -a
ls 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 pdb
To 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 class
Type ls to see the contents (which should be empty)
Exercise
Make another directory inside the pdb directory.

1.4 The directories


Still in the class directory, type
% ls -a
As 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
% pwd
The full path name will look something like this /usr/people/model6/class
which 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 model6
to list the contents of your home directory.
Now type
% ls class
You will get a message like this class: No such file or directory
The 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 ~/class

will 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 file2
What 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 pdb
Then 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 file2
To 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.txt
% ls (to check if it has created the file)
% rm tempfile.txt
% ls (to check if it has deleted the file)
You 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.
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
% clear
This 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.pdb
As 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.pdb
Press 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.pdb
Then type
% head -5 1A3Y.pdb
What 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.pdb
How 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.pdb
then, still in more (i.e. don't press q to quit), type a slash followed by the word to search
/END
As 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.pdb
As 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.pdb
The grep command is "case sensitive"; it distinguishes between upper case and lower case letters
To ignore upper/lower case distinctions, use the -i option, i.e. type
% grep -i 'ca cys' 1A3Y.pdb
Some 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 lines
Try 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.pdb
wc (word count)
A useful unix utility is the wc command. To do a word count on 1BVQ.pdb, type
% wc -w 1A3Y.pdb
To find out how many lines the file has, type
% 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]

2.1 Redirection
Most UNIX commands will write to the standard output (that is, they write on to screen), and many take
their input from the standard input (that is, they read it from the keyboard). The standard error by default,
will aso write to the screen.
We have seen one use of the cat command is to write the contents of a file onto the screen.

Now type cat without specifing a file to read


% cat [Return]
Then type a few words on the keyboard and press the [Return] key.
Finally hold the [Ctrl] key down and press d (written as ^D for short) to end the input.
What has happened?
If you run the cat command without specifing a file to read, it reads the standard input (the keyboard), and
on receiving the "end of file" (^D), copies it to the standard output (the screen).
In UNIX, we can redirect both the input and the output of commands.

2.2 Redirecting the Output


We use the > symbol to redirect the output of a command. For example, to create a file
called amino1.seq containing a list of amino acids, type
% cat > amino1.seq
Then type in the names of some amino acids. Press [Return] after each one.
ALA A
ARG R
PHE F
ASN N
^D (Control D to stop)
What happens is the cat command reads the standard input (the keyboard) and the > redirects cat's output,
which normally goes to the screen, into a file called amino.seq
To read the contents of the file, type
% cat amino1.seq

Exercise
Using the cat, create another file called amino2.seq containing the following residues: ASP D, CYS C, VAL
V, GLU E (Note each will contain a 3 letter and one letter codes as above)

The form >> appends standard output to a file.

You should now have two files: amino1.seqand amino2.seq. We will now use the cat command to
put amino2.seqinto amino1.seq. Type
% cat amino2.seq >> amino1.seq
What this is doing is reading the contents of amino2.seq and then appending the text to the file amino1.seq
To read the contents of amino1.seq, type
% more amino1.seq

2.3 Redirecting the Input


We use the < symbol to redirect the input of a command.
The command sort alphabetically or numerically sorts a list. Type
% sort [Return]
Then type in the names of some amini acids. Press [Return] after each one.
ALA
PHE
CYS
^D (control d to stop)
The output will be
ALA
CYC
PHE
Using < you can redirect the input to come from a file rather than the keyboard. For example, to sort the list
of fruit, type
% sort < amino1.seq
and the sorted list will be output to the screen.
To output the sorted list to a file, type,

% sort < amino1.seq > amino1_sorted.seq


Use cat to read the contents of the file amino1_sorted.seq

2.4 Pipes
To see recent logins of users and terminals on your system computer type
% last
One method to get a sorted list of user names is to type,
% last > names.txt
% sort < names.txt
This is a bit slow and you have to remember to remove the temporary file called names.txt when you
finished. What if you really want to do is connect the output of the last command directly to the input of the
sort command. This is exactly what pipes do. The symbol for a pipe is |
For example, typing
% last | sort
will give the same result as above, but quicker and cleaner.
To find out how many users are logged on, type
% who | wc -l

Summary

command > file

redirect standard output to a file

command >> file

append standard output to a file

command < file

redirect standard input from a file

command1 | command2

pipe the output of command1 to the input of command2

cat file1file2 > file0

concatenate file1 and file2 to file0

sort

sort data

last

list users recently logged in

2.5 Wildcards
The character * is called a wildcard, and will match against none or more character(s) in a file (or directory)
name. For example, in your pdb directory, type
% ls *.aln
This will list all files in the current directory ending with ".aln"
The character ? will match exactly one character.
So ls ?ouse will match files like house and mouse, but not grouse.
Try typing
% ls ?

2.6 Filename conventions


We should note here that a directory is merely a special type of file. So the rules and conventions for naming
files apply also to directories.
In naming files, characters with special meanings such as /,*,&,% etc., should be avoided. Also, avoid using
spaces within names. The safest way to name a file is to use only alphanumeric characters, that is, letters and
numbers, together with _ (underscore) and . (dot).
File names conventionally start with a lower-case letter, and may end with a dot followed by a group of
letters indicating the contents of the file. For example, all files consisting of Perl code may be named with
the ending .pl, for example, prog1.pl . Then in order to list all files containing Perl code in your current
directory, you need only type ls *.pl in that directory.
Beware: some applications give the same name to all the output files they generate. For example, some
compilers, unless given the appropriate option, produced compiled files named a.out. Should you forget to

use that option, you are advised to rename the compiled file immediately, otherwise the next such file will
overwrite it and it will be lost.

2.7 Getting Help


On-line Manuals
There are on-line manuals which gives information about most commands. The manual pages tell you which
options a particular command can take, and how each option modifies the behaviour of the command. Type
man command to read the manual page for a particular command.
For example, to find out more about the wc (word count) command, type
% man wc
Apropos
When you are not sure of the exact name of a command,
% apropos keyword
will give you the commands with keyword in their manual page header. For example, try typing
% apropos rename

Summary

match any number of characters

match one character

man command

read the online manual page for a command

whatis command

brief description of a command

apropos keyword

match commands with keyword in their man pages

2.8 Other useful UNIX commands


cut
A column manipulation command. Very good at working with columns of any text files.
set
Widely used for text string substitutions of a text file.
echo
It just echoes arguments what you put in
quota
All students are allocated a certain amount of disk space on the file system for their personal files, usually
about 5 Megabyes (equivalent to 4 floppy disks worth). If you go "over-quota", you are given 7 days to
remove excess files.
To check your current quota and how much of it you have used, type
% quota -v
df
The df command reports on the space left on the file system. For example, to find out how much space is left
on the fileserver, type
% df .
du
The du command outputs the number of kilobyes used by each subdirectory. Useful if you have gone over
quota and you want to find out which directory has the most files. In your home-directory, type
% du
compress
This reduces the size of a file, thus freeing valuable disk space. For example, type
% ls -l blast.txt
and note the size of the file. Then to compress t, by typing
% compress blast.txt

This will compress the file and place it in a file called science.txt.Z
To see the change in size, type ls -l again.
To uncomress the file, use the uncompress command.
% uncompress science.txt.Z
gzip
This also compresses a file, and is more efficient than compress. For example, to zip blast.txt, type
% gzip blast.txt
This will zip the file and place it in a file called science.txt.gz
To unzip the file, use the gunzip command.
% gunzip blast.txt.gz
file
file classifies the named files according to the type of data they contain, for example ascii (text), pictures,
compressed data, etc.. To report on all files in your home directory, type
% file *
history
The C shell keeps an ordered list of all the commands that you have entered. Each command is given a
number according to the order it was entered.
% history (show command history list)
If you are using the C shell, you can use the exclamation character (!) to recall commands easily.
% !! (recall last command)
% !-3 (recall third most recent command)
% !5 (recall 5th command in list)
% !grep (recall last command starting with grep)
You can increase the size of the history buffer by typing
% set history=100

Shell Scripting:

A very good introdution can be found at:


http://supportweb.cs.bham.ac.uk/documentation/tutorials/docsyste
m/build/tutorials/unixscripting/unixscripting.html
http://www.atmos.albany.edu/das/classes/atm450/scripting.htm

3.1 File system security (access rights)


In your home directory, type
% ls -l (l for long listing!)
You will see that you now get lots of details about the contents of your directory, similar to the example
below.

Each file (and directory) has associated access rights, which may be found by typing ls -l SEQ1.
-rw-r--r--

1 model6 user

39 Feb 2 2000 SEQ1

In the left-hand column is a 10 symbol tring consisting of the symbols d, r, w, x, -, and,


occasionally, s or S. If d is present, it will be at the left hand end of the string, and indicates a directory:
otherwise - will be the starting symbol of the string.
The 9 remaining symbols indicate the permissions, or access rights, and are taken as three groups of 3.
The left group of 3 gives the file permissions for the user that owns the file (or
directory) (SEQ1 in the above example);
the middle group gives the permissions for the group of people to whom the file (or
directory) belongs (user in the above example);
the rightmost group gives the permissions for all others.
The symbols r, w, etc., have slightly different meanings depending on whether they refer to a simple file or
to a directory.
Access rights on files.

r (or -), indicates read permission (or otherwise), that is, the presence or absence of
permission to read and copy the file

w (or -), indicates write permission (or otherwise), that is, the permission (or
otherwise) to change a file

x (or -), indicates execution permission (or otherwise), that is, the permission to
execute a file, where appropriate

Access rights on directories.

r allows users to list files in the directory;

w means that users may delete files from the directory or move files into it;

x means the right to access files in the directory. This implies that you may read files
in the directory provided you have read permission on the individual files.

So, in order to read a file, you must have execute permission on the directory containing that file, and hence
on any directory containing that directory as a sub directory, and so on, up the tree.
Some examples
-rwxrwxrwx a file that everyone can read, write and execute (and delete).
-rw------- a file that only the owner can read and write - no one else
can read or write and no one has execution rights (e.g. your
mailbox file).

3.2 Changing access rights


chmod (changing a file mode)
Only the owner of a file can use chmod to change the permissions of a file. The options of chmod are as
follows

Symbol

Meaning

user

group

other

all

read

write (and delete)

execute (and access directory)

add permission

take away permission

For example, to remove read write and execute permissions on the file SEQ1 for the group and others, type
% chmod go-rwx SEQ1
This will leave the other permissions unaffected.

To give read and write permissions on the file SEQ1 to the world,
% chmod a+rw SEQ1

3.3 Processes and Jobs


A process is an executing program identified by a unique PID (process identifier). To see information about
your processes, with their associated PID and status, type
% ps
A process may be in the foreground, in the background, or be suspended. In general the shell does not return
the UNIX prompt until the current process has finished executing.
Some processes take a long time to run and hold up the terminal. Back grounding a long process has the
effect that the UNIX prompt is returned immediately, and other tasks can be carried out while the original
process continues executing.

Running background processes


To background a process, type an & at the end of the command line. For example, the command sleep waits
a given number of seconds before continuing. Type
% sleep 10
This will wait 10 seconds before returning the command prompt %. Until the command prompt is returned,
you can do nothing except wait.
To run sleep in the background, type
% sleep 10 &
[1] 6259
The & runs the job in the background and returns the prompt straight away, allowing you do run other
programs while waiting for that one to finish.
The first line in the above example is typed in by the user; the next line, indicating job number and PID, is
returned by the machine. The user is be notified of a job number (numbered from 1) enclosed in square
brackets, together with a PID and is notified when a background process is finished. Back grounding is
useful for jobs which will take a long time to complete.

Back grounding a current foreground process


At the prompt, type
% sleep 500
You can suspend the process running in the foreground by holding down the [control] key and typing z
(written as ^Z) Then to put it in the background, type

% bg
Note: do not background programs that require user interaction.
3.4 Listing suspended and background processes
When a process is running, back grounded or suspended, it will be entered onto a list along with a job
number. To examine this list, type
% jobs
An example of a job list could be
[1] Suspended sleep 500
[2] Running netscape
[3] Running nedit
To restart (foreground) a suspended processes, type
% fg %jobnumber
For example, to restart sleep 100, type
% fg %1
Typing fg with no job number foregrounds the last suspended process.
3.5 Killing a process
kill (terminate or signal a process)
It is sometimes necessary to kill a process (for example, when an executing program is in an infinite loop)
To kill a job running in the foreground, type ^C (control c). For example, run sleep 500 then kill it with ^C
To kill a suspended or background process, type
% kill %jobnumber
For example, run sleep 500 & then type jobs to see its job number. If it is job number 1, type
% kill %1
To check whether this has worked, examine the job list again to see if the process has been removed.
ps (process status)
Alternatively, processes can be killed by finding their process numbers (PIDs) and using kill PID_number.
Run sleep 100 & again, then type
% ps
PID TT S TIME COMMAND
20077 pts/5 S 0:05 sleep 500
21563 pts/5 T 0:00 netscape
21873 pts/5 S 0:25 nedit
To kill off the process sleep 100, type
% kill 20077
and then type ps again to see if it has been removed from the list.
If a process refuses to be killed, uses the -9 option, i.e. type

% kill -9 20077
Note: It is not possible to kill off other users processes !!!
Summary
ls -lag

list access rights for all files

chmod [options] file

change access rights for named file

command &

run command in background

^C

kill the job running in the foreground

^Z

suspend the job running in the foreground

bg

background the suspended job

jobs

list current jobs

fg %1

foreground job number 1

kill %1

kill job number 1

ps

list current processes

kill 26152

kill process number 26152

4.1 User logins, password and logouts


To ensure security and organization on a system with many users, UNIX machines employ a system of user
accounts.
The user accounting features of UNIX provide a basis for analysis and control of system resources,
preventing any
user from taking up more than his or her share, and preventing unauthorized people from accessing the
system.
Every user of a UNIX system must get permission by some access control mechanism.
Logging in
Logging in to a UNIX system requires two pieces of information:
1) A username, and
2) a password.
When you sit down for a UNIX session, you are given a login prompt that looks like this (depending on the
flavors
of UNIX OS you are using):
login:
Type your username at the login prompt, and press the return key. The system will then ask you for your
password.
When you type your password, the screen will not display what you typed.
Your username
Your username is assigned by the person who creates your account. Your username must be unique on the
system where your account exists since it is the means by which you are identified on the system.
Your password
When your account is created, a password is assigned. The first thing you should do is change your
password,
using the passwd utility.
To change your password, type the command passwd after you have logged in. The system will ask for

your old password, to prevent someone else from sneaking up, and changing your
password. Then it will ask for your new password. You will be asked to confirm your new password, to
make sure
that you didn't mistype. It is very important that you choose a good password, so that someone else cannot
guess it.
Here are some rules for selecting a good password:

Do not use any part of your name, your spouse's name, your child's name, your pet's name, or
anybody's name.

Do not use any backward spellings of any name, either.

Do not use an easily-guessable number, like your phone number, your social security number,
your address, license plate number, etc.

Do not use any word that can be found in an English or foreign-language dictionary.

Do not use all the same letter, or a simple sequence of keys on the keyboard, like qwerty.

Do use a mix of upper-case and lower-case letters, numbers, and control characters.

Do use at least six characters.

Excercise
Change your passord after you login the first by typing
passwd [Enter]
Logging Out
It all depends on the OS you are running. Most Uinces have a nice GUI to let you click a button to
logout. Otherwise
just use exit command

3.2 Telnet and ftp


Telnet
Telnet is a program that allows you to log into your user account on a remote UNIX server.
Telnet provides a command line, text-only type of connection. A basic Telnet program is built into
Windows, Macintosh, and Unix computers. You can also get Telnet programs as freeware or shareware that
expand the functionality of the basic Telnet. All work in a similar maner: they allow you to log into your
remote unix computer account and directly access your files using UNIX commands so you can work at
home. By typing
%telnet vishnu.utmb.edu [Enter]
then you will see something like:
Trying 129.109.73.47...
Connected to vishnu.utmb.edu.
Escape character is '^]'.
IRIX (vishnu.utmb.edu)
login:

At the login: prompt type in your user name and hit [Enter] key. Then it will ask for the passwod
and type a
password and hit the [Enter] key again. If the password given matches the password stored in the
computer
you will see something like:
IRIX Release 6.5 IP30 vishnu
Copyright 1987-2002 Silicon Graphics, Inc. All Rights Reserved.
Last login: Wed Sep 04 11:13:57 CDT 2002 by yuan@planck.utmb.edu
on your screen.
ftp
The ftp program lets you contact a remote server computers to initiate remote file transfers.
All computers do not implement the server function. Typically, UNIX systems have both the client
programs
and the server function (although the server may be turned off or restricted by the system manager
for
security reasons), allowing two-way connections between UNIX computers, initiated at either
end. Desktop
computers such as Windows PCs and Macintoshes typically only have the client programs, and
can initiate
connections to UNIX servers, but not to other desktop computers.

Example
#!/bin/sh
#
#***************************************************************************
************
# This bourne shell script will read in a PDB structure file then extract the
sequence
# and write the sequence out as one and three letter code and save them
into two files.
# It can also break up the boundle file into individual structure file if the PDB
file
# contains more than one boundle structure (NMR boundle).
#***************************************************************************
************
clear
echo "***********************************************"
echo "* Welcome to use pdbscan v1.0
*"
echo "* Written by Yuan Xu Jan. 8, 2002
*"
echo "* Please email any suggestions and comments to *"
echo "* yuxu@utmb.edu
*"
echo "***********************************************"
#
var=null

chk=""
seq=.seq
one=_1ltr
three=_3ltr
junk=null
echo " Please enter a PDB file name and hit Enter if done > \c"
read pdb
if test $pdb != "$chk"
then
echo "loading pdb file: $pdb"
fi
if [ -s $pdb ]
then
grep "SEQRES" $pdb | cut -c 12 > junk
var=`head -1 junk`
else
echo "Sorry, Could not find file: $pdb, try again!"
exit
fi
#
echo " Please enter a root file name for your output sequence files > \c"
read input
#echo "The root name you entered: $input"
echo "The root name you entered: $input"
seq1=$input$one".seq"
seq3=$input$three".seq"
echo "Your one letter and three letter code sequence files are:"
echo "$seq1 and $seq3"
# in case old files exist
if [ -s $seq1 ]
then
/bin/rm -rf $seq1
fi
if [ -s $seq3 ]
then
/bin/rm -rf $seq3
fi
# creat two output files
touch "$seq1"
touch "$seq3"
#
# get now the sequence:
# Now cut the field 5 of lines with SEQRES. Notice Space is also considered
as a field,
# then save field 5 and get the containt of field 5 and make sure it is A, B or
anything
#else

#
if test "$var" = "A" || $var = "B"
then
echo "The sequence starts from field 9"
grep "SEQRES" $pdb | cut -c20-70 > $seq3
echo "DONE!"
else
echo " The sequence starts from field 7"
grep "SEQRES" $pdb | cut -c20-70 > $seq3
echo "DONE!"
fi
#
# Now translate three letter code to one letter code:
num_res=`wc $seq3 | cut -c26-30` #count number of lines
echo "Total number of Residues: $num_res"
#then use sed to generate one letter code
A=ALA
C=CYS
D=ASP
E=GLU
F=PHE
G=GLY
H=HIS
I=ILE
K=LYS
L=LEU
M=MET
N=ASN
P=PRO
Q=GLN
R=ARG
S=SER
T=THR
V=VAL
W=TRP
Y=TYR
#
sed 's/ALA/A/g
s/CYS/C/g
s/GLU/E/g
s/PHE/F/g
s/GLY/G/g
s/HIS/H/g
s/ILE/I/g
s/LEU/L/g
s/LYS/K/g
s/MET/M/g
s/ASN/N/g

s/PRO/P/g
s/GLN/Q/g
s/ARG/R/g
s/SER/S/g
s/THR/T/g
s/TRP/W/g
s/ASP/D/g
s/TYR/Y/g
s/VAL/V/g' $seq3 > $seq1

#
# To remove the space between the two residues
sed 's/ //g' $seq1

Вам также может понравиться