unix basics for new users

Upload: grabcave

Post on 01-Jun-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 UNIX Basics for New Users

    1/28

    Definitions

    Typographical definitions

    The following typographical conventions are used while typing unix commands:

    1) Characters in bold faceare commands to be typed as is!!.

    2) Characters in italic face indicatearbitrary fileor directory names.

    ) ords inserted between s"uare brac#ets [ ]indicate the #eyboard #eys to be pressed.

    $xample%

    %ls any directory[Enter]

    means &at the '(* prompt +% type lsfollowed by the name of some directory% then press the #ey mar#ed

    $nter&

    ,) -ont forget to press the /$nter0 #ey: acommand you typed onto the computer screen will not be

    executed without pressing this key.

    (otice: '(* is case sensitve% so LSis not the same as ls.

    The same applies to filenames%

    so seuence!txt% Seuence!txt and SE"#E$E!T&T are three different file

    names. owever% -3 and indows do not ma#e these distinctions.

    'ow to #se #nix or Linux

    ( Little 'istory

    'nix is an operating system with "uite a lot of history. 'nix began in the early 45s when a small research

    group at 6ell labs wrote the first 'nix #ernel 7the core of the operating system) and some tools. The tool set

    of 'nix was designed as set of small utilities 8 each of them designed to do a single tas# well 8 which would

    all fit together to perform more complex tas#s. $arly in its life 'nix was re8written in c 7it 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 'nix very portable. Throughout the 45s 'nix became very popular. The code was shared

    out to many 'niversities and other institutions% many of whom made their own fixes% improvements and

    tools which made their way bac# into the operating system 99distribution.

    $ventually% T;T and others figured out that 'nix could be sold for big money. Companies began

    implementing their own versions of 'nix and #eeping their own code secret. 'nix began to 99for#% or split

    into many versions with varying degrees of incompatibility. 6y the mid8eighties the 'nix community was a

    disparate set of factions who found it difficult to agree on anything. round the same time% the 6< =C was

    becoming popular% gradually moving computing away from the large machines on which 'nix ran.

  • 8/9/2019 UNIX Basics for New Users

    2/28

    (etare series of networ# operating systems for the =C% followed by eorge Tannenbaum% who coded a small version

    of 'nix called minix for the =C. ne person who was interested in minix was a computing student in

    ?inland called @inus Torvalds. @inus became frustrated with some of the limitations of minix 7many of

    which stemmed from its 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 bro#en. @inus decided to

    code his own operating system based on 'nix. The first release was in 1AA1% when he invited anyone and

    everyone via the nternet to have a loo# through his code and help to develop it.

    s it turned out% @inus was very good at fostering a community around @inux. e is credited with beingvery congenial% willing to let others ta#e or share credit for their wor# and fairly liberal in deciding which

    additions should go bac# into @inux itself. These features% along with the rise of the nternet as a means of

    communicating and sharing data were instrumental in building @inux into a very popular and strong

    operating system. @inux was placed under the >(' >eneral =ublic @icence 7>=@)% which isa copyright%

    but stipulates that the code should always be made available with the program 7and those derived from it). n

    this way% there is a legal guarantee that the code hiding 7and conse"uent for#ing) which happened to

    'nix cannothappen to @inux.

    To the user% @inux is almost indistinguishable from other 'nices. The rise in popularity of @inux has also

    helped raise the level of #nowledge of 'nix amongst millions of students around the world over the last

    decade. There are now a great number of people wor#ing in computing who have 'nix #nowledge and

    s#ills. There are also other free 'nices which have benefited from all of this. The most famous are the

    variants of 63- 76er#eley 3ystems -istribution) for the =C which have a reputation for "uality. s write

    this 'nix% whether on a =C% a wor#station or a big server% is increasing again in popularity. B5+ of all web

    servers on the nternet use pache 7a free web server) running on @inux or 'nix% up from a little over 5+ acouple of years ago. round 2+ of servers now run @inux% up from almost nothing a few years ago.

    mongst nternet service providers usage is even higher 7,,+) 8 since @inux comes with source code it can

    be modified to run on custom rac#8mountable hardware which is perfect for serving large numbers of

    connections. mongst 'niversities usage of @inux is also strong 8 many 'niversities still have large

    amounts of 'nix expertise and @inux fits in well. lso% @inux is extremely inter8operable with most other

    systems% spea#ing most networ# protocols and able to use many different file8systems% ma#ing it perfect in

    an environment with many computing platforms.

  • 8/9/2019 UNIX Basics for New Users

    3/28

    The rise of @inux brings us pretty much up to date. t the time of writing of this history% it is unclear

    whether this will lead to any significant change on

  • 8/9/2019 UNIX Basics for New Users

    4/28

    ,!, Directory *iles

    3uppose that in the directory x 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 bF 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.

    ,!. De/ice *iles

    n 'nix% physical devices 7printers% terminals etc.) are represented as 99files. This seems odd at

    first% but it really ma#es sense: This way% the same read01and write01functions used to read and write real

    files can also be used to read from and write to these devices.

    ,!2 Link *iles

    )!) Listing files and directories

    ls 0list1

    hen you login to your account% your current directory is your home directory and it has the same name as

    your login name% for example% modelB% and all your personal files and sub directories are saved under your

    home directory.

    To find out what is in your home directory% type

    % ls7short for list)

    The lscommand lists the contents of your current wor#ing directory.

    There could be no files visible in your home directory% in which case% the '(* prompt will be returned.

    lternatively% there may already be some files inserted by the 3ystem dministrator when your account was

    created.

    lsdoes not% in fact% lists all the files in your home directory% but only those ones whose name does not begin

    with a dot 7!) ?iles beginning with a dot 7!) are #nown as hidden files and usually contain important programconfiguration information. They are hidden because you should not change them unless you are very

    familiar with '(*!!!

    To list all files in your home directory including those whose names begin with a dot% type

    % ls 3a

    lsis an example of a command which can ta#e options: 3ais 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 ta#e% and how each option modifies the behavior of the command. 73ee later in this tutorial)

  • 8/9/2019 UNIX Basics for New Users

    5/28

    )!, 4aking Directories

    mkdir 0make directory1

    e will now ma#e a sub directory in your home directory to hold the files you will be creating and using in

    the course of this tutorial. To ma#e a sub directory called pdb in your current wor#ing directory type

    % mkdir pdb

    To see the directory you have Iust created% type% ls

    )!. hanging to a different directory

    cd 0change directory1

    The command cd 5directory6 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 Iust made% type

    % cd class

    Type lsto see the contents 7which should be empty)

    Exercise

  • 8/9/2019 UNIX Basics for New Users

    6/28

    )!7 8ath names

    pwd 0print working directory1

    =ath names enable you to wor# out where you are in relation to the whole file system. ?or example% to find

    out the absolute path name of your home directory% type cdto go to your home directory and then type

    % pwd

    The full path name will loo# something li#e this 8

    +usr+people+model9+class

    which means that model97your home directory) is in the directory people7the group directory)% which is

    located under directory named usr and usris directly under the root directory +.

    Exercise )b

    'se the commands ls% pwdand cdto explore the file system.

    7Jemember% if you get lost% type cdby itself to return to your home directory)

    )!9 4ore about home directories and path names

    #nderstanding path names

    ?irst type cd !!to get out of your home directory% then type

    % ls model9

    to list the contents of your home directory.

    (ow type

    % ls class

    Eou will get a message li#e this 8

    class: $o such file or directory

    The reason is% classis not in your current wor#ing directory. To use a command on a file 7or directory) not in

    the current wor#ing directory 7the directory you are currently in)% you must either cdto the correct directory%

    or specify its full path name. To list the contents of your class directory% you must type

    % ls model9+backups

    if your current directory is people

    ; 0your home directory1

    ome directories can also be referred to by the tilde ;character. t can be used to specify paths starting at

    your home directory. 3o typing

    % ls ;+class

  • 8/9/2019 UNIX Basics for New Users

    7/28

    will list the contents of your class directory% no matter where you currently are in the file system.

    hat do you thin#

    % ls ;

    would listL

    hat do you thin#

    % ls ;+!!

    would listL

    Summary

    ls list files and directories

    ls 3a list all files and directories

    mkdir ma#e 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

    )!< opying *iles

    cp 0copy1

    cpfile1 file2is the command which ma#es a copy of file)in the current wor#ing directory and calls it file,

    hat we are going to do now% is to ta#e a file stored in an open access area of the file system% and use

    the cpcommand to copy it to your pdbdirectory.

    ?irst% cdto your pdbdirectory.

    % cd pdb

    Then at the '(* prompt% type%

  • 8/9/2019 UNIX Basics for New Users

    8/28

    % cp ;+)(.=!pdb !

    7(ote: -ont forget the dot &!& at the end. Jemember% in '(*% the dot means the current directory.)

    The above command means copy the file 16MN.pdb to the current directory% #eeping the name the same.

    Exercise

    Create a bac#up of your )(.=!pdbfile by copying it to a file called )(.=!pdb!bck

    )!> 4o/ing files

    m/ 0mo/e1

    m/file1 file2moves 7or renames) file)to file,

    To move a file from one place to another% use the m/command. This has the effect of moving rather than

    copying the file% so you end up with only one file rather than two.

    t can also be used to rename a file% by &moving& the file to the same directory% but giving it a different name.

    e are now going to move the file )(.=!pdb!bckto your bac#up directory 7create a backups directory

    first

    under your pdbdirectory.

    ?irst% change directories to your pdbdirectory 7can you remember howL). Then% inside the pdbdirectory%

    type

    % m/ )(.=!pdb!bck backups+!

    Type lsand ls backupsto see if the file has been moved successfully.

    )!? @emo/ing files and directories

    rm 0remo/eA delete1A rmdir 0remo/eA delete directory1

    To delete 7remove) a file% use the rmcommand. ere is an example of deleting a file.

    nside your pdb directory% type

    % cp )(.=!pdb tempfile!txt

    % ls 7to chec# if it has created the file)

    % rm tempfile!txt

    % ls 7to chec# if it has deleted the file)

    Eou can use the rmdircommand to remove a directory 7ma#e sure it is empty first). Try to remove the

    bac#ups directory. Eou will not be able to since '(* will not let you remove a non empty directory.

    powerful addition for rm

    + rm 3rf B

    will remove everything starting from your current directory and below if you are the owner of the

  • 8/9/2019 UNIX Basics for New Users

    9/28

    everything

    in those directories. 'se it very carefully% once it was deleted there is no way you can get them bac# easily.

    Exercise

    Create a directory called tempstuffusing mkdir% then remove it using the rmdircommand.

    )!)C Displaying the contents of a file on the screen

    clear 0clear screen1

    6efore you start the next section% you may li#e to clear the terminal window of the previous commands so

    the output of the following commands can be clearly understood.

    t the prompt% type

    % clear

    This will clear all text and leave you with the + prompt at the top of the window.

    cat 0concatenate1

    The command catcan be used to display the contents of a file on the screen. Type:

    % cat )(.=!pdb

    s you can see% the file is longer than than the siDe of the window% so it scrolls past ma#ing it unreadable.

    more

    The command more writes the contents of a file onto the screen a page at a time. Type

    % more )(.=!pdb

    =ress the space8bar if you want to see another page% type if you want to "uit reading. s you can see% more

    is used in preference to cat for long files.

    head

    The headcommand writes the first ten lines of a file to the screen.

    ?irst clear the screen then type

    % head )(.=!pdb

    Then type

    % head 37 )(.=!pdb

    hat difference did the 8 do to the head commandL

    tail

    The tailcommand writes the last ten lines of a file to the screen.

    Clear the screen and type

    % tail )(.=!pdb

    ow can you view the last 1 lines of the fileL

  • 8/9/2019 UNIX Basics for New Users

    10/28

    )!)) Searching the contents of a file

    Simple searching using more

    'sing more% you can search though a text file for a #eyword 7pattern). ?or example% to search

    through )(.=!pdbfor the word $(-% type

    % more )(.=!pdb

    then% still in more 7i.e. dont press " to "uit)% type a slash followed by the word to search+E$D

    s you can see% morefinds and highlights the #eyword. Type nto search for the next occurrence of the

    word.

    grep 0dont ask why it is called grep1

    grepis one of many standard '(* utilities. t searches files for specified words or patterns. ?irst clear the

    screen% then type

    % grep ( =S )(.=!pdbs you can see% grep has printed out each line containing ( =S. 3o you can use it to get total number of

    CE3 residues in this protein.

    Try typing

    % grep ( ys )(.=!pdb

    The grep command is &case sensitive&F it distinguishes between upper case and lower case letters

    To ignore upperHlower case distinctions% use the 3ioption% i.e. type

    % grep 3i ca cys )(.=!pdb

    3ome of the other options of grep are:

    3/ display those lines that do (T match

    3nprecede each matching line with the line number

    3cprint only the total count of matched lines

    Try some of them and see the different results. -ont forget% you can use more than one option at a time% for

    example% the number of lines without the words CE3 or cys is

    % grep 3i/c cys )(.=!pdb

    wc 0word count1

    useful unix utility is the wccommand. To do a word count on )F"!pdb% type

    % wc 3w )(.=!pdb

    To find out how many lines the file has% type

    % wc 3l )(.=!pdb

    Summary

    cpfile1 file2 copy file1 and call it file2

  • 8/9/2019 UNIX Basics for New Users

    11/28

    m/file1 file2 move or rename file1 to file2

    rmfile remove a file

    rmdir directory remove a directory

    catfile display a file

    morefile display a file a page at a time

    headfile display the first few lines of a filetailfile display the last few lines of a file

    grep keywordfile search a file for #eywords

    wcfile count number of linesHwordsHcharacters in file

    Text Editors

    There are three basic editors you can use for editing the text file:

    /i editor 7screen editor% a default editor on all '(* machines. little bit hard to learn but you should

    master it)

    /ifilename[Enter]

    Got editor 7only available on J*. very simple and easy to use% >' based editor. Eou should use it here)

    Gotfilename [Enter]

    nedit editor 7Jeally good multi8function >' based text editor. =rogrammers love it and is available on our

    3>s)

    neditfilename[Enter]

    ,!) @edirection

  • 8/9/2019 UNIX Basics for New Users

    12/28

    (ow type catwithout specifing a file to read

    % cat [@eturn]

    Then type a few words on the #eyboard and press the [@eturn]#ey.

    ?inally hold the [trl]#ey down and press d7written as HDfor short) to end the input.

    hat has happenedL

    f you run the catcommand without specifing a file to read% it reads the standard input 7the #eyboard)% and

    on receiving the &end of file& 7HD)% copies it to the standard output 7the screen).

    n '(*% we can redirect both the input and the output of commands.

    ,!, @edirecting the -utput

    e use the6 symbol to redirect the output of a command. ?or example% to create a file

    calledamino)!se containing a list of amino acids% type

    % cat 6 amino)!se

    Then type in the names of some amino acids. =ress [@eturn]after each one.

    (L( (

    (@I @

    8'E *

    (S$ $

    HD 7Control - to stop)

    hat happens is the cat command reads the standard input 7the #eyboard) and the 6redirects cats output%

    which normally goes to the screen% into a file called amino!se

    To read the contents of the file% type

    % cat amino)!se

    Exercise

    'sing the cat% create another file called amino,!se containing the following residues: 3= -% CE3 C% M@

    M% >@' $ 7(ote each will contain a letter and one letter codes as above)

  • 8/9/2019 UNIX Basics for New Users

    13/28

    The form66 appends standard output to a file.

    Eou should now have two files: amino)!seand amino,!se. e will now use the cat command to

    put amino,!seinto amino)!se. Type

    % cat amino,!se 66 amino)!se

    hat this is doing is reading the contents of amino,!se and then appending the text to the file amino)!se

    To read the contents of amino)!se% type

    % more amino)!se

    ,!. @edirecting the Jnput

    e use the 5symbol to redirect the input of a command.

    The command sort alphabetically or numerically sorts a list. Type

    % sort [@eturn]

    Then type in the names of some amini acids. =ress /Jeturn0 after each one.

    (L(

    8'E

    =S

    HD7control d to stop)

    The output will be

    (L(

    =

    8'E

    'sing 5you can redirect the input to come from a file rather than the #eyboard. ?or example% to sort the list

    of fruit% type

    % sort 5 amino)!se

    and the sorted list will be output to the screen.

    To output the sorted list to a file% type%

  • 8/9/2019 UNIX Basics for New Users

    14/28

    % sort 5 amino)!se 6 amino)Ksorted!se

    'se cat to read the contents of the file amino)Ksorted!se

    ,!2 8ipes

    To see recent logins of users and terminals on your system computer type

    % last

    ne method to get a sorted list of user names is to type%

    % last 6 names!txt

    % sort 5 names!txt

    This is a bit slow and you have to remember to remove the temporary file called names.txt when you

    finished. hat 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

    ?or example% typing

    % last sort

    will give the same result as above% but "uic#er and cleaner.

    To find out how many users are logged on% type

    % who wc 3l

    Summary

    command 6file redirect standard output to a file

    command 66file append standard output to a file

    command 5file redirect standard input from a file

    command) command, pipe the output of command1 to the input of command2

    catfile1file26file0 concatenate file1 and file2 to file5

  • 8/9/2019 UNIX Basics for New Users

    15/28

    sort sort data

    last list users recently logged in

    ,!7 Mildcards

    The character Bis called a wildcard% and will match against none or more character7s) in a file 7or directory)

    name. ?or example% in your pdbdirectory% type

    % ls B!aln

    This will list all files in the current directory ending with &.aln&

    The character Nwill match exactly one character.

    3o ls Nousewill match files li#e houseand mouse% but not grouse.

    Try typing

    % ls N

    ,!9 *ilename con/entions

    e should note here that a directory is merely a special type of file. 3o the rules and conventions for naming

    files apply also to directories.

    n naming files% characters with special meanings such as +%B%O%%etc.% should be avoided. lso% avoid using

    spaces within names. The safest way to name a file is to use only alphanumeric characters% that is% letters and

    numbers% together withK7underscore) and !7dot).

    ?ile names conventionally start with a lower8case letter% and may end with a dot followed by a group of

    letters indicating the contents of the file. ?or example% all files consisting of =erl code may be named with

    the ending !pl% for example% prog)!pl. Then in order to list all files containing =erl code in your current

    directory% you need only type ls B!plin that directory.

    eware: some applications give the same name to all the output files they generate. ?or example% some

    compilers% unless given the appropriate option% produced compiled files named a!out. 3hould you forget to

  • 8/9/2019 UNIX Basics for New Users

    16/28

    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.

    ,!< Ietting 'elp

    -n3line 4anuals

    There are on8line manuals which gives information about most commands. The manual pages tell you which

    options a particular command can ta#e% and how each option modifies the behaviour of the command. Type

    man command to read the manual page for a particular command.

    ?or example% to find out more about the wc 7word count) command% type

    % man wc

    (propos

    hen you are not sure of the exact name of a command%

    % apropos keyword

    will give you the commands with keywordin their manual page header. ?or example% try typing

    % apropos rename

    Summary

    B match any number of characters

    N 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 #eyword in their man pages

  • 8/9/2019 UNIX Basics for New Users

    17/28

    ,!> -ther useful #$J& commands

    cut

    column manipulation command. Mery good at wor#ing with columns of any text files.

    set

    idely used for text string substitutions of a text file.

    echo

    t Iust echoes arguments what you put in

    uota

    ll students are allocated a certain amount of dis# space on the file system for their personal files% usually

    about

  • 8/9/2019 UNIX Basics for New Users

    18/28

    This will compress the file and place it in a file called science!txt!P

    To see the change in siDe% type ls 3lagain.

    To uncomress the file% use the uncompress command.

    % uncompress science!txt!P

    gQip

    This also compresses a file% and is more efficient than compress. ?or example% to Dip blast!txt% type

    % gQip blast!txt

    This will Dip the file and place it in a file called science!txt!gQ

    To unDip the file% use the gunDip command.

    % gunQip blast!txt!gQ

    file

    file classifies the named files according to the type of data they contain% for example ascii 7text)% pictures%

    compressed data% etc.. To report on all files in your home directory% type

    % file B

    history

    The C shell #eeps an ordered list of all the commands that you have entered. $ach command is given a

    number according to the order it was entered.

    % history 7show command history list)

    f you are using the C shell% you can use the exclamation character 7 R) to recall commands easily.

    + RR 7recall last command)

    + R3. 7recall third most recent command)

    + R7 7recall th command in list)

    + Rgrep 7recall last command starting with grep)

    Eou can increase the siDe of the history buffer by typing

    + set history)CC

    Shell Scripting:

  • 8/9/2019 UNIX Basics for New Users

    19/28

    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

    .!) *ile system security 0access rights1

    n your home directory% type

    % ls 3l 7l for long listing!)

    Eou will see that you now get lots of details about the contents of your directory% similar to the example

    below.

    $ach file 7and directory) has associated access rights% which may be found by typing ls 3l SE").

    3rw3r33r33 ) model9 user .? *eb , ,CCC SE")

    n the left8hand column is a 15 symbol tringconsisting of the symbols d% r% w% x% 3% and%occasionally% sor S. f dis present% it will be at the left hand end of the string% and indicates a directory:

    otherwise 8will be the starting symbol of the string.

    The A remaining symbols indicate the permissions% or access rights% and are ta#en as three groups of .

    The left group of gives the file permissions for the user thatownsthe file 7or

    directory) 73$N1 in the above example)F

    the middle group gives the permissions for the groupof people to whom the file 7or

    directory) belongs 7user in the above example)F

    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.

    (ccess rights on files!

    r7or 8)% indicates read permission 7or otherwise)% that is% the presence or absence of

    permission to read and copy the file

    http://supportweb.cs.bham.ac.uk/documentation/tutorials/docsystem/build/tutorials/unixscripting/unixscripting.htmlhttp://supportweb.cs.bham.ac.uk/documentation/tutorials/docsystem/build/tutorials/unixscripting/unixscripting.htmlhttp://www.atmos.albany.edu/das/classes/atm450/scripting.htmhttp://www.atmos.albany.edu/das/classes/atm450/scripting.htmhttp://supportweb.cs.bham.ac.uk/documentation/tutorials/docsystem/build/tutorials/unixscripting/unixscripting.htmlhttp://supportweb.cs.bham.ac.uk/documentation/tutorials/docsystem/build/tutorials/unixscripting/unixscripting.html
  • 8/9/2019 UNIX Basics for New Users

    20/28

    w7or 8)% indicates write permission 7or otherwise)% that is% the permission 7or

    otherwise) to change a file

    x7or 8)% indicates execution permission 7or otherwise)% that is% the permission to

    execute a file% where appropriate

    (ccess rights on directories!

    rallows users to list files in the directoryF

    wmeans that users may delete files from the directory or move files into itF

    xmeans 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.

    3o% 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

    3rwxrwxrwx a file that everyone can read% write and execute 7and delete).

    3rw3333333 a file that only the owner can read and write 8 no one else

    can read or write and no one has execution rights 7e.g. your

    mailbox file).

    .!, hanging access rights

    chmod 7changing a file mode)

    nly the owner of a file can use chmod to change the permissions of a file. The options of chmod are as

    follows

    Symbol 4eaning

    u user

    g groupo other

    a all

    r read

    w write 7and delete)

    x execute 7and access directory)

    O add permission

    8 ta#e away permission

  • 8/9/2019 UNIX Basics for New Users

    21/28

    ?or example% to remove read write and execute permissions on the file 3$N1 for the group and others% type

    %chmod go3rwx SE")

    This will leave the other permissions unaffected.

    To give read and write permissions on the file 3$N1 to the world%

    %chmod arw SE")

    .!. 8rocesses and Uobs

    process is an executing program identified by a uni"ue =- 7process identifier). To see information about

    your processes% with their associated =- and status% type

    %ps

    process may be in the foreground% in the bac#ground% or be suspended. n general the shell does not return

    the '(* prompt until the current process has finished executing.

    3ome processes ta#e a long time to run and hold up the terminal. 6ac# grounding a long process has the

    effect that the '(* prompt is returned immediately% and other tas#s can be carried out while the original

    process continues executing.

    @unning background processes

    To bac#ground a process% type an Oat the end of the command line. ?or example% the command sleep waits

    a given number of seconds before continuing. Type

    %sleep )C

    This will wait 15 seconds before returning the command prompt +. 'ntil the command prompt is returned%

    you can do nothing except wait.

    To run sleep in the bac#ground% type

    %sleep )C O

    [)] 9,7?

    The Oruns the Iob in the bac#ground 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 userF the next line% indicating Iob number and =-% is

    returned by the machine. The user is be notified of a Iob number 7numbered from 1) enclosed in s"uare

    brac#ets% together with a =- and is notified when a bac#ground process is finished. 6ac# grounding is

    useful for Iobs which will ta#e a long time to complete.

    ack grounding a current foreground process

    t the prompt% type%sleep 7CC

    Eou can suspend the process running in the foreground by holding down the /control0 #ey and typing D

    7written as HP) Then to put it in the bac#ground% type

  • 8/9/2019 UNIX Basics for New Users

    22/28

    %bg

    (ote: do not bac#ground programs that re"uire user interaction.

    .!2 Listing suspended and background processes

    hen a process is running% bac# grounded or suspended% it will be entered onto a list along with a Iob

    number. To examine this list% type

    %Gobsn example of a Iob list could be

    [)] Suspended sleep 7CC

    [,] @unning netscape

    [.] @unning nedit

    To restart 7foreground) a suspended processes% type

    %fg %jobnumber

    ?or example% to restart sleep 155% type

    %fg %)

    Typing fgwith no Iob number foregrounds the last suspended process.

    .!7 Villing a process

    kill 0terminate or signal a process1

    t is sometimes necessary to #ill a process 7for example% when an executing program is in an infinite loop)

    To #ill a Iob running in the foreground% type H7control c). ?or example% run sleep 7CCthen #ill it with H

    To #ill a suspended or bac#ground process% type

    %kill %jobnumber

    ?or example% run sleep 7CC Othen typeGobsto see its Iob number. f it is Iob number 1% type

    %kill %)

    To chec# whether this has wor#ed% examine the Iob list again to see if the process has been removed.

    ps 0process status1

    lternatively% processes can be #illed by finding their process numbers 7=-s) and using #ill =-Pnumber.

    Jun sleep )CC Oagain% then type

    %ps

    =- TT 3 T

  • 8/9/2019 UNIX Basics for New Users

    23/28

    %kill 3? ,CC

  • 8/9/2019 UNIX Basics for New Users

    24/28

    your old password% to prevent someone else from snea#ing up% and changing your

    password. Then it will as# for your new password. Eou will be as#ed to confirm your new password% to

    ma#e sure

    that you didnt mistype. t is very important that you choose a good password% so that someone else cannot

    guess it.

    ere are some rules for selecting a good password:

    -o not use any part of your name% your spouses name% your childs name% your pets name% or

    anybodys name.

    -o not use any bac#ward spellings of any name% either.

    -o not use an easily8guessable number% li#e your phone number% your social security number%

    your address% license plate number% etc.

    -o not use any word that can be found in an $nglish or foreign8language dictionary.

    -o not use all the same letter% or a simple se"uence of #eys on the #eyboard% li#e "werty.

    Do use a mix of upper8case and lower8case letters% numbers% and control characters.

    Do useat least six characters.

    Excercise

    Change your passord after you login the first by typing

    passwd [Enter]

    Logging -utt all depends on the 3 you are running.

  • 8/9/2019 UNIX Basics for New Users

    25/28

    t thelogin:prompt type in your user name and hit /$nter0 #ey. Then it will as# for the passwod

    and type a

    password and hit the /$nter0 #ey again. f the password given matches the password stored in the

    computer

    you will see something li#e:

    J* Jelease B. =5 vishnu

    Copyright 1AK482552 3ilicon >raphics% nc. ll Jights Jeserved.

    @ast login: ed 3ep 5, 11:1:4 C-T 2552 by yuanRplanc#.utmb.edu

    on your screen.

    ftp

    The ftp program lets you contact a remote server computers to initiate remote file transfers.

    ll computers do not implement the server function. Typically% '(* systems have both the client

    programs

    and the server function 7although the server may be turned off or restricted by the system manager

    for security reasons)% allowing two8way connections between '(* computers% initiated at either

    end. -es#top

    computers such as indows =Cs and

  • 8/9/2019 UNIX Basics for New Users

    26/28

    ch"6))seq6seqone67+ltrthree678ltr

    9un"6nullecho ) Please enter a PDB fle name and hit :nter i done ;

  • 8/9/2019 UNIX Basics for New Users

    27/28

    #i test )=var) 6 )H) =var 6 )B)then

    echo )The sequence starts rom feld I)4rep ):C':) =pdb cut @c3,@J, ; =seq8echo )DK%:!)elseecho ) The sequence starts rom feld J)4rep ):C':) =pdb cut @c3,@J, ; =seq8echo )DK%:!)

    f## %ow translate three letter code to one letter code>

    num7res6Ewc =seq8 cut @c3L@8,E #count number o linesecho )Total number o 'esidues> =num7res)

    #then use sed to 4enerate one letter code

    H6HMHF6F.D6HP:6NMO6PQ:N6NM.Q6Q6M:R6M.M6M:O&6&:T%6H%P6P'KC6NM%'6H'N6:'

    T6TQ'S6SHM6T'P

    .6T.'#sed s/HMH/H/4

    s/F./F/4s/NMO/:/4s/PQ://4s/NM./N/4s/Q/Q/4s/M://4

    s/M:O/M/4s/M./R/4s/&:T/&/4s/H%/%/4

  • 8/9/2019 UNIX Basics for New Users

    28/28

    s/P'K/P/4s/NM%/C/4s/H'N/'/4s/:'//4s/TQ'/T/4s/T'P//4s/HP/D/4s/T.'/./4s/SHM/S/4 =seq8 ; =seq+

    ## To remove the space between the two residues

    sed s/ //4 =seq+