unix - naredbe itd

Upload: anonymous-ze7gec1mx

Post on 16-Feb-2018

234 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/23/2019 UNIX - Naredbe Itd.

    1/60

    1. Introduction

    Conventions Used Here

    1. UNIX command words and their arguments are shown exactly as you shouldtype them, including the distinction between uppercase letters and lowercaseletters, which are not interchangeable on UNIX systems. For example, UNIXtreats MAIL, Mail, and mailas three distinct entities.

    2. If an item is shown in italics, substitute an appropriate real alue for it, such asan actual filename, user name, directory, or whateer.

    !. If an item in a command syntax line is shown in s"uare brac#ets $ %, it&soptional. 'on&t type the brac#ets in the command itself, but do type any other

    punctuation shown, such as a hyphen.(. If an ellipsis ... is shown, it means you can repeat the preious item shown in

    the syntax line.). No command line is actually processed by the UNIX system until you press

    the Return#ey. In most cases, this manual does not show the *eturn.+. ype control characters by holding down the #ey mar#ed -ontrol or -*

    while you press another #ey. -ontrol characters are indicated in this manualwith a caret character ^. For example, ^cmeans hold down the Control#eywhile you press c.

    /. he bac#space #ey may be mar#ed '0, '000, *U, or *UU onyour #eyboard. DELis used here.

    o illustrate the conentions, here is the format of the cp command, which copies one

    or more files into a directory3

    cp [-i] [-r]file ... directory

    he command name cp must be gien in lower case4 the -i and -r arguments may beomitted or gien exactly as shown4 then one or more filenames of actual files4 andfinally an actual directory name.

    Special Caracters

    5any punctuation characters and control characters hae special meaning to UNIX.

    0en before your first login, you should #now the ones below. thers are gien in-hapter (, 66he 7hell and -ommand 8rocessing&&.

    Correctin! "#pin! Mista$es

    efore you press the Return#ey, you can correct a typing error by using3DEL to erase the previous character.

    ^w to erase the previous word. ^u to discard the whole command line.

    Si!nalin! End o% Input ^d

    If you are typing input to a process, press ^dto signal the end of input.

    http://www.utexas.edu/cc/docs/ccug1/chap4.htmlhttp://www.utexas.edu/cc/docs/ccug1/chap4.html
  • 7/23/2019 UNIX - Naredbe Itd.

    2/60

    If you hae used a 957 or '7 system, you may be familiar with typing ^&for thispurpose, but on UNIX systems, ^&suspends a process3 it does not end input.

    A'ortin! a (rocess or Discardin! )utput ^c and ^o

    :ou can abort a process and discard its output by pressing ^c. :ou can also discardoutput or s#ip oer part of the display by using ^o. ;hen you do this, the program

    producing the output does not stop, but its output is discarded until you gie another^oor until no more output remains.

    *. +ettin! Access to te U,I S#stems

    Connectin! to a U,I S#stem

    efore you can use any

  • 7/23/2019 UNIX - Naredbe Itd.

    3/60

    o change your elesys password, run telnet and connect to teles#s.uteas.edu. henfollow the instructions on screen.

    ,ote0 -hanging your elesys password or username has no effect on accounts orpasswords on any other computers to which you connect.

    For more information about elesys, seeDial up to the Internet with Telesys >usagenote Den@11?.

    Connectin! %rom Anoter Computer

    If you are already logged in on another computer that is connected to the Internet, youshould be able to connect to an

  • 7/23/2019 UNIX - Naredbe Itd.

    4/60

    -hoose a passwordat least + characters long that is meaningful N: to you4 youdon&t want anyone else to guess it easily. In fact, if your password is easy to guess, theUNIX system will not een accept it. For example, it will not accept words from adictionary. 'on&t choose your initials, nic#name, or birthdate. 5ixing uppercaseletters and digits in your password to ma#e it hard to guess. his password is the only

    thing that #eeps someone else from using your account and haing ull access to yourwor#.

    e sure the password is something you can remember yourself. If you forget it, youwill hae to go in person, with proper identification, to the =elp 'es# at the 9arsity-enter to as# the staff to assign you a new one. If the password is for a user numberunder a departmental computer account, such as those accounts used for classes, theaccount sponsor must write a letter on departmental stationery stating that you areauthoriCed to use that user number and that the password can be changed.

    he new@user program may as# you to choose which command interpreter, called a

    66shell&&, you want to hae as your login shell. n some UNIX systems, you are gienthe - shell, which is sometimes designated by its directory, AbinAcsh. he - shell isrecommended.

    he program may also as# for optional data to put in a database that other users canloo# at. his data can include your real name >rather than your login name?, address,

    phone number, and proects you are wor#ing on. If you don&t want to include anyindiidual item, ust press *eturn in response to the prompt for it.

    If you later want to add data or change data in this database, use the command

    chfn

    Eceptions0 For the U7 system, you must run c%n on the machine namedcurl#.cc.uteas.edu. For the --;F system, send your re"uest to change the data to

    [email protected]

    ;hen the new@user program has completed, you will be logged off the systemautomatically.

  • 7/23/2019 UNIX - Naredbe Itd.

    5/60

    If the terminal you are using is really a 91BB or is emulating a 91BB >such as a5acintosh or ;indows computer running a terminal emulation program?, ust press*eturn. If your terminal is some other type, type in the correct alue. If you don&t#now what #ind of terminal you are using, ust press *eturn to accept the t1BB alue3it is the most common setting and will probably wor# well. :ou can call the =elp

    'es# at (/)@G(BB if you suspect your terminal settings are causing problems.

  • 7/23/2019 UNIX - Naredbe Itd.

    6/60

    printed output to a printer in the 7ee chapter )to learn how to do this.?

    Can!in! 6our (ass/ord

    :our passwordis the only thing that #eeps others from impersonating you on thesystem and getting full access to your files and computing resources. o protect yourfiles and your user number, it is a good idea to change your password occasionally. o

    do this, type the commandpasswd

    :ou will be prompted first for your current password, then twice for a new one >thesecond time for erification?. Neither your old password nor your new one will appearon the screen when you type it. *emember that the password should be somethingyou can remember but others can&t easily guess. It can be + to E characters long >+ to1+ character long on U7?. n some forexample, your nic#name?, words from a dictionary, or words and names that peoplehae used in the past to try to brea# into computer accounts.

    Lo!!in! )ut

  • 7/23/2019 UNIX - Naredbe Itd.

    7/60

    ;hen you try to log out, you might see the message, 66here are suspended obs.&&his means you hae suspended some process that you should finish or #ill beforeyou log out. 7ee chapter (to learn how to do this.

    If your terminal seems to loc# up and you cannot log out, you might hae a runaway

    or disconnected ob. -hapter G describes how to fix this problem.

    9. +ettin! Help :ile on te S#stem

    2indin! )ut :at7s Availa'le

  • 7/23/2019 UNIX - Naredbe Itd.

    8/60

    split split (1) split a multiroutine ;,RTR27ile into individual ilesintro intro (1) introduction to ;,RTR27Manual agesintro intro () introduction to ;,RTR27lirar! unctions and suroutines

    lim9doule lim9doule () ;,RTR27 access to douleprecision lim unctions and suroutineslim9>uadruple lim9>uadruple () ;,RTR27 access to >uadrupleprecision lim unctions (S2R onl!)lim9single lim9single () ;,RTR27 access to singleprecision lim unctions and suroutinesputc putc () write a character to a;,RTR27 logical unitrator rator (1) rational ;,RTR27 dialecttclose topen () ;,RTR27 tape +-,topen topen () ;,RTR27 tape +-,tread topen () ;,RTR27 tape +-,trewin topen () ;,RTR27 tape +-,

    ts&ip topen () ;,RTR27 tape +-,tstate topen () ;,RTR27 tape +-,twrite topen () ;,RTR27 tape +-,

    Notice that apropos does not re"uire an exact case match3 it successfully founduppercase F**

  • 7/23/2019 UNIX - Naredbe Itd.

    9/60

    output is passed on to the lpr command, which sends the output to a printer. o see alist of printing sites, type

    man sites

    In%oEplorer on ADS

    If you use the

  • 7/23/2019 UNIX - Naredbe Itd.

    10/60

    UNIX commands begin with a command name, often an abbreiation of thecommand&s action >such as cp for 66copy&& or mv for 66moe&&?. 5ost commandsinclude 66flags&& and 66arguments&&. < flag identifies some optional capability and

    begins with a hyphen. to 66concatenate&& files?. In this case, cat reads the file named66stuff&& and displays it. he -n flag tells cat to number the lines in the display.

    he hyphen that precedes a flag is a special character used to distinguish flags fromfilenames. In the example aboe, the hyphen preents cat from trying to display a filenamed 66n&&. -ommands can contain other special characters as well. he shellinterprets such characters, and sometimes replaces them with other alues, before it

    passes the command with its flags and arguments to the program that actuallyexecutes the command.

    *emember that uppercase and lowercase letters are not interchangeable. hus if youtried to gie the cat command by typing -uppercase? -and only 7=0? must be all uppercase.

    Special Caracters

    he following sections describe many of the characters that hae special meaning tothe - shell. Leep in mind that 57 punctuation characters hae some specialmeaning. herefore, you should not include any punctuation character other than

    period or underscore in the names you gie to files and directories, or you may getsurprising results. te ? ?? and @ Caracters

    If a program normally reads its input from the terminal >referred to as 66standardinput&& or 66stdin&&? or writes its output to the terminal >66standard output&& or 66stdout&&?,you may want it to read from or write to an alternate file instead. For example, if yougie the command

    who

    the login names of others currently logged in are written to standard output@@displayedat your terminal. If you want to hae this list placed into a file called 66namelist&&, youcould use the character ?to redirect standard output to namelist, li#e this3

    who + namelist

    If you already hae a file named namelist, the shell erases its contents, then calls /oto write the new information to namelist. If you do not hae a file named namelist, theshell creates a new one before it calls the /oprogram.

    :ou can then do what you want with the file namelist@@print it, sort its contents,display it with the cat command, or whateer.

    o append output to an existing file instead of oerwriting it, use the symbol ??.hus, if you first type

  • 7/23/2019 UNIX - Naredbe Itd.

    11/60

    who + namelist

    and laterwho ++ namelist

    he file namelist will contain two sets of results3 the second set is appended to thefirst instead of destroying it.

    Normally, you will not need to redirect standard input, as most commands that canread from standard input also accept an input filename as an argument. =oweer, forcommands that normally expect input from your terminal, the character M followed bya filename tells the command to read from that file instead. For example, one way tosend mail is to type

    mail user

    and then to type the text of the message from your terminal. If the text of the messageis already in a file named letter, you could redirect standard input to send the mail thisway3

    mail user , letter

    ,ote0he shell performs input and output redirection 0F*0 it callsthe command you want to execute. his means that files can beaccidentally destroyed. For example, the command

    sort , mfile + mfile

    destroys 66myfile&& because the shell >1? opens myfile for reading andthen >2? opens it again for writing. ;hen you open a file for writing,UNIX destroys the old contents of the file. te B Caracter

    < pipeline is a useful way to use the output from one command as input to anotherwithout creating an intermediate file. 7uppose that you want to use the /o commandto see who is logged in, and you want to see the results sorted alphabetically. he sort

    program reads a file and displays the sorted results on your terminal@@the standardoutput. 7o you could accomplish what you want with the following se"uence ofcommands3

    who + namelist

    sort namelistertical bar?. ;hen commands are separated by the symbol, output from thecommand on the symbol&s left side becomes input to the one on the right of it. husyou could type

    who % sort

    so that the results of the /oprogram are passed to the sortprogram as input anddisplayed, by default, on your terminal.

  • 7/23/2019 UNIX - Naredbe Itd.

    12/60

    5ore than one pipe symbol can be used to ma#e a series of commands, the standardoutput from each becoming the standard input to the next.

    ,ote0If a command is not capable of reading from standard input, itcannot be placed to the right of a pipe symbol.

    Caracters Used to Epand 2ile and Director# ,ames >te F - and

    G Caracters

    he shell also interprets other special characters it finds on a command line before itpasses this line to the program that will execute it. hese characters are normally usedin place of filenames or directory names3

  • 7/23/2019 UNIX - Naredbe Itd.

    13/60

    -

    < hyphen used within Fdenotes a range of characters. For example,

    cat draft[1-4]

    has the same meaning as

    cat draft[12$536784]thedirectory in which you are placed when you log in on UNIX?. It is a useful specialcharacter if you changed to some different directory after you logged in, and want tocopy a file to or from your home directory. If you append another user&s login name tothe O character, it refers to that user&s home directory@@useful if you are sharing fileswith someone else. For example,

    @cssmith

    means 66the home directory of the user whose login name is cssmith&&. he usefulnessof this notation will become more apparent in the next chapter.

    ,ote0n most UNIX systems, the O character has this special meaningto the - shell only, not to the ourne shell. In shell scripts, which aregenerally processed by the ourne shell, use the ariable =50 tospecify your own home directory.

    Action Caracters

    your terminal?, it reads eerything you type until you use^d. his is also true if the program is the shell. o ma#e the - shell ignore ^d, so thatyou don&t log out accidentally, disable it with the command

    set i#noreeof

    foreground? command, or resume it in the bac#ground with the '!

    command. o #ill a suspended program, gie the command8o's -l to get theprogram&s ob number. hen use

    kill 9job-no

    to terminate it.

    If you fail to #ill or resume a suspended process, when you try to log out you will getthe message3 66here are suspended obs&&. :ou can disable ^&entirely under UNIX byma#ing the 66suspend&& character undefined. o do so, type the following command or

    place it in your .login file3

    stt susp ^-

    :ou could also use the stt# command to redefine the suspend character to somethingother than ^&.

    http://www.utexas.edu/cc/docs/ccug1/chap2.htmlhttp://www.utexas.edu/cc/docs/ccug1/chap2.html
  • 7/23/2019 UNIX - Naredbe Itd.

    14/60

    uotation Caracters > and 7

  • 7/23/2019 UNIX - Naredbe Itd.

    15/60

    For example, suppose you want to copy a file from one directory to another, using thecp command, and issued the command

    cl m

  • 7/23/2019 UNIX - Naredbe Itd.

    16/60

    o place a slow@running ob in the 66bac#ground&& so that you don&t hae to wait for itto finish before issuing another command, use the ampersand character. For example3

    sort verlar#efile B

    he shell will notify you when the bac#ground ob is finished.

    )ter Special Caracters

    esides the special characters discussed in this chapter, there are some others thathae special meaning to the shell and which, if not "uoted in a command line, will not

    be treated as ordinary characters. hey include3C F G

    ;ithin a program, you should not need to "uote special characters to ma#e themordinary4 it is only when the shell interprets your command that such characters areexpanded instead of being treated as text.

    Sell Initiali&ation 2iles

    such as your setenvEDI")R command? should be in .login. such as set istor#O

  • 7/23/2019 UNIX - Naredbe Itd.

    17/60

    *emember that the shell is itself a program. on the

  • 7/23/2019 UNIX - Naredbe Itd.

    18/60

    8athnames can be either 66relatie&& or 66absolute&&. A? and starts at the root. 0ach successie directory name down the path is also

    preceded by a slash. ;hen you examined the shell&s search path with the eco 4(A"Hcommand in thepreious chapter, you saw some absolute pathnames. he absolute

    pathname to the home directory for user 66person&& might loo# li#e this3

    -home-uts-cs-csnn-person

    he directory 66person&& contains the names of files in that directory, and it may alsoidentify other directories below it in the hierarchy. 668erson&& is itself under thedirectory csnn, which is under the directory cs. hat is, the csnn directory is the66parent&& of person4 subdirectories below person are the 66children&& of person. hishierarchy is >in part?3

    (root) - A B - A B - A B usr home

    A A uts - B - B cc cs - B - B - B - B csnn C=== person%s parentdirector! - B - B person C=== person%s home

    director! - B - B proDects papers C=== person%ssudirectories - B - B

    < relatie path starts from the directory you are wor#ing in and moes downward to alower directory. Instead of starting with a slash, a relatie pathname starts with thename of the first directory below this wor#ing directory4 each lower directory downthe path is prefixed by a slash.

    In both absolute and relatie pathnames, the rightmost component is either theultimate directory name, or a file in that directory. For example, suppose 66person&& hastwo subdirectories3 66proects&& and 66papers&&, and 66report1&& is a file in 66papers&&. If66person&& is the wor#ing directory, then here is a command to display 66report1&&3

    cat papers/report1

  • 7/23/2019 UNIX - Naredbe Itd.

    19/60

    Seein! :at is in 6our Director#

    o see the names of any files or lower@leel directories you hae in your currentwor#ing directory, use the ls >list? command. Its simplest form is

    ls

    which lists the names of any files and directories that do not begin with a period >.?.o see all? flag3

    ls -a

    0en if you hae not yet created any files in your directory, you should see the names66.login&& and 66.cshrc&& >the - shell&s initialiCation files? and two entries named 66.&& and66..&&. he entry named only 66.&& is the directory you are wor#ing in, and 66..&& identifiesits parent, een though these directories hae full pathnames, too. long? flag3

    ls -lhe protection modes determine what actions you and others may perform on thefiles. ;hat these modes mean and how to change them is described below.

    he -2 flag is also useful. It mar#s the names of directories with a trailing slash >A?character and the names of executable files with a trailing asteris# >S?. In fact, thecommand3

    alias ls Ils -0I

    is often included in .lo!inand .csrcfiles so that directories and executables arealways indicated by the trailing characters.

    o see directory information about selected files and lower@leel directories, you canuse the special characters described in chapter (.For example, suppose you are66person&& in the hierarchy shown aboe, wor#ing in your home directory, Operson. Ifyou gie the command

    ls p

    this expands tols papers proJects

    and lists the names of files in the subdirectory 66papers&&, then those in the subdirectory66proects&&, except for files whose names start with a period.

    o list the names of all files in the lower directory 66papers&&, you might use

    ls -a papers

    and get something li#e. .. astract outline report1 report report

    Note that this directory, li#e your home directory, uses . to mean its own name and ..to identify its parent. 7o to list the names of files in the directory aboe the currentone, you could type

    ls ..

    If you only need to #now which files in subdirectory 66papers&& hae names beginning

    with 66report&&, you could usels papers/reportor

    http://www.utexas.edu/cc/docs/ccug1/chap4.htmlhttp://www.utexas.edu/cc/docs/ccug1/chap4.htmlhttp://www.utexas.edu/cc/docs/ccug1/chap4.html
  • 7/23/2019 UNIX - Naredbe Itd.

    20/60

    ls papers/report[1-4]or ls papers/report

    he last two forms would, of course, not list a file named 66report12&&.

    Note from these examples that the ls command lists files in the wor#ing directoryonly, unless you include the pathname to another directory whose filenames you wantto list.

    ,amin! 2iles and Directories

    ;heneer you ma#e new directories below your home directory and create files inany of your directories, you must gie these directories and files appropriate names.In general, names should include only letters of the alphabet, digits, period >.? andunderscore >R?. li#e .lo!inor .csrc?. heunderscore character is useful for readability in filenames >e.g. testRscores?. 5ostother punctuation characters hae special meaning to the shell.

  • 7/23/2019 UNIX - Naredbe Itd.

    21/60

    your 66wor#ing directory&&. o moe to toRdo from your home directory, use the cd>change directory? command3

    cd to

  • 7/23/2019 UNIX - Naredbe Itd.

    22/60

    o preent destroying a file that already exists, include the -i flag. For example, if youtype

    mv -i source.a oldsource.a

    and 66oldsource.a&& already exists, mv will as# if you really want to oerwrite that old

    copy with the newer one.

    (rotectin! 2iles and Directories

    :our files and directories are protected from other users& perusal and destruction byprotection@mode settings. hese settings control who may read, write, and executeyour files. o see what the settings are, issue the ls command using the -l >long? flag.o the left of each file or directory name is displayed a se"uence of 1B characters,such as

    drw6or

    rwrrhe leftmost character is 66@&& for a filename entry, 66d&& for a directory name entry. henext G characters are three triplets of protection settings4 the first pertains to you >theowner?, the middle triplet pertains to members of your group >if a group has beenestablished?, and the rightmost pertains to eeryone else.

    hus the first line shown here says the entry is a directory for which you hae read >r?,write >w?, and execute >x? permission and for which eeryone else has no priileges atall. he second entry is a file. In this case, you may read and write it, but others canonly read it.

    o change the protection modes of your files or directories, use the cmod >changemode? command. It has seeral forms, but the easiest to use is

    chmod[who]oppermission names

    where names identifies one or more file or directory names. he whooppermissionse"uence must be gien with no blan#s between portions. he whoportion can be anycombination of

    u user (owner o the ile or director!) # group memers o others a all o the aove (deault i !ou omit the whoargument)

    he op is one ofN add the designated permission

    - remove the designated permission : replace all e6isting permissions or the relevant who with the new ones o this chmodcommand

    andpermission is any or all ofr read' + chmodis or a ile? it allows that ile to e

    read? provided the director! containing it has 6 permission. + chmodis or a director!? it allows that director! to e listed with ilenames onl!.

    w write' + chmodis or a ile? it allows that ile to e written (altered or replaced). + chmodis or a director!? it allows new iles to e added to that director! ande6isting iles to e removed.

  • 7/23/2019 UNIX - Naredbe Itd.

    23/60

    x e6ecute' + chmodis or a ile? it ma&es that ilee6ecutale (see chapter 10). + chmodis or a director!? it allows a detailed listing (i r is also set)? and allows iles to eread

    or written in that director! according to their individualile permission settings.

    he usual protection for a directory that you want others to be able to loo# through isr@x for eerybody.

    0xamples3

    chmod u:rx .pro#

    permits the owner of all files whose suffix is 66prog&&, in the wor#ing directory, to readand execute these files. If write priileges had existed for the owner, these priilegesare remoed. No one other than the owner is affected, and no protection settings ofany other files are affected.

    chmod Nr a&stract

    gies eerybody permission to read file 66abstract&&. No other existing permissions arealtered for the file. he directory containing 66abstract&& must hae x permission aswell, if attempts to read 66abstract&& are to succeed.

    chmod Nrx .

    gies eeryone permission to read and search the wor#ing directory.

    ,ote0If you need to establish a 66group&&, the computer accountsponsor should arrange this by sending e@mail to

    [email protected]

    Include in the message the name wanted for the group and a list of theusers to be in the group. -all the =elp 'es# at (/)@G(BB for moreinformation.

    Displa#in! 2iles in 6our Director#

    ;e hae already discussed the cat command, which concatenates one or more files tostandard output, your terminal. Its format is simply

    catfile1 [file2] ...

    o display files that ta#e up seeral screens, you may want to use the commandmorefile1 [file2] ...

    he moreprogram pauses after each screenful.

  • 7/23/2019 UNIX - Naredbe Itd.

    24/60

    (rintin! 2iles

    o get a printed copy of a file, use the lpr command3lpr -'site file

    wheresite identifies the printer where you want to pic# up your output. o see the

    names and locations of sites, typeman sites

    remoe? command3rmfile1 [file2] ...

    If you do not include a pathname, the files are assumed to be in your wor#ingdirectory. If you use any special characters such as S or T with the rm command, it isa good precaution to add the -i flag, li#e this3

    rm -i file*

    his interactie option displays, one at a time, each candidate for remoal. o remoethe file, type # >for 66yes&&? and press Return. < common case is accidentally creating a filename whose firstcharacter is a hyphen.? In this case, use the - flag and put the filename in "uotationmar#s, li#e this3

  • 7/23/2019 UNIX - Naredbe Itd.

    25/60

    rm - G&adnameG

    o remoe a directory that you no longer need, use rmdir0rmdirpath

    wherepath is the relatie or absolute pathname of the directory. he rmdir commandwill not delete a directory while it is your wor#ing directory, nor will it delete a

    directory that contains any files >besides .and ..?.

    o remoe a directory

  • 7/23/2019 UNIX - Naredbe Itd.

    26/60

    and can log out without losing any files. =oweer, there are two reasons that youshould ta#e prompt action to remoe unneeded files to get below the soft "uota.

    he most serious reason is that if you continue using resources, you may reach the66hard&& "uota. If you do, you will not be able to run programs. In fact, a running

    program will abort if it attempts to use dis# space that exceeds the hard "uota.Furthermore, when you try to modify existing files, they may get truncated to Cero@length files@@without warning or notice.

    he second reason is that een if you do stay below the hard "uota but remain oerthe soft "uota for seen days >on the --;F and U7 systems?, you will not be ableto alter existing files or create new ones until you get bac# below the soft "uota.

    o see how much dis# space you are using, gie the command

    Puota -v

    If you need a higher dis# "uota than the one originally established, you can change itby giing the command

    chPuota

    he "uota you re"uest must be in multiples of 1BBB #ilobytes, with a minimum of1BBB #ilobytes >approximately 1 megabyte?. Leep in mind that you are charged forthe dis# space you resere >i.e., your "uota?, rather than the dis# you actually use4 sodon&t re"uest too much more than you expect to need.

    Q. Creatin! and Alterin! 2iles

    5any UNIX users will probably create files on a microcomputer and then transferthose files to a UNIX system. ut you may find it useful to create or edit files on theUNIX system itself. ne way to create new files in your directory, or to alter files youalready hae, is to use a text editor, a program written specifically to perform thesetas#s. he most commonly used UNIX text editor is vi >pronounced 66ee@eye&&?. nand 957? systems, the DNU 05

  • 7/23/2019 UNIX - Naredbe Itd.

    27/60

    efore using i, be sure that you hae correctly identified your terminal type to theUNIX system. 9i uses information associated with your terminal type when it moesthe cursor and scrolls lines of text up and down. If you hae not yet identified theterminal type, as described in section 2.!, do so before calling i. If you use i withoutidentifying your terminal type, i responds 66$using open mode%Q, and displays only

    one line at a time.

    o call the i editor, use the command

    viname

    where name is the name of the file you want to create or modify. If the file alreadyexists in your wor#ing directory, i displays the first screenful and, at the bottom lineof the display, tells you how big the file is. If i can&t find a file by that name, it tellsyou the file is new.

    Unli#e some display editors, i does not automatically insert into the file eerything

    that you type. Instead, it has a command mode and an insert mode. ;hen you start upi, you are in command mode. If you gie a command that puts i into insert mode,you remain in insert mode until you press the 07- #ey to go bac# to command mode.5ost commands you type to i will not show on the screen, and they do not need the*eturn #ey to terminate them. ne exception to this is commands that begin with acolon >3?. downward and upward? oer the file. ;ithin thatwindow, you moe the cursor to the position where you want to insert, delete, orreplace text. ;hen you begin editing a file that already exists, the window is the firstscreenful, or page, of the file. he following control characters moe the window upand down3

    ^d Moves the window down hal a screenul. ^u Moves the window up hal a screenul. ^f Moves the window orward one ull screen (with a ew lines o overlap).

    ^& Moves the window ac&ward one ull screen.o redraw the current window, use ^l>lowercase 66&&?.

    o moe the cursor within the window, use any of the following3

    hQJQkQl Moves the cursor one character position let? down? up? or right? respectivel!. ,n some terminals? the arrow &e!s serve the same unction. N Moves the cursor to the eginning o the ne6t line. - Moves it to the eginning o the previous line. !eturn Same as F. * Moves the cursor to the top (highest line) o the

    screen. L Moves it to the ottom (lowest line) o the screen. " Moves it to the middle line on the screen.

  • 7/23/2019 UNIX - Naredbe Itd.

    28/60

    w Moves the cursor right? to the eginning o the ne6tword. & Moves it let? to the eginning o the previous word. ?(Gero) Moves it to the eginning o the current line. ( Moves it to the end o the current line.

    o moe the cursor to a position that may be outside the current window, use one of

    the following commands3/string!eturn

    Searches orward or string,centering the line containing it in the new window. + the searchreaches the end o the ile without inding the string? it ""wraps around%% to the eginning o the ile and continues searching.

    string!eturn Searches ac&ward or string,also wrapping around i stringis not etween the starting point and the eginning o the ile.

    nR Moves to line n.

    R Moves to the last line o the ile.

    he alue ofstring is 66remembered&&, and so =Return searches forward for the mostrecently named string, and Return searches bac#ward for it.

    Insertin! "et

    7eeral commands put i into insert mode. In insert mode, eerything you type isinserted into the file until you press the 07- >escape? #ey. =ere are some of the most

    useful commands to initiate insert mode3i Hegins inserting te6t immediatel! eore the cursor. a Hegins inserting te6t immediatel! ater the cursor. o ,pens a new line elow the current one and enters insert mode. Iou ma! t!pe an! numer o new lines. M (uppercase o) ,pens a new line aove the current one and enters insert mode.

    Deletin! "et

    In general, use the d command to delete material. he d command ta#es an argumentto describe what #ind of entity to delete, and it can be prefixed with a number to

    indicate the number of repetitions for this deletion. yping dand then stri#ing thespace bar deletes the character under the cursor. If you type Pd, then space, you deletefie characters@@the current one plus the next four. ther forms are3

    dw*eletes rom the cursor position through the end o the word. 5dwdeletes our words' the current one and the ne6tthree.

    dd*eletes the entire current lineJ 2dddeletes two lines.

    o simply delete the character under the cursor, you can also type . here is also a Dcommand >capital '?. It deletes the rest of the current line, beginning with thecharacter under the cursor.

    Alterin! Eistin! "et

  • 7/23/2019 UNIX - Naredbe Itd.

    29/60

    o replace existing text with new text, you could simply use an appropriate dcommand, then insert new material at the same point. =ere are some other commandsthat replace existing text with new text3

    r ;ollowed ! a single character? this replaces thecharacter under the cursor with the new character. ;or e6ample?rs replaces whatever is under the cursor with an ""s%%.

    !text ;ollowed ! the ES &e!? this acts as i !ou had given a se>uence o rcommands? one or each character othe new te6t. That is? it is a oneorone character replacement o an! length !ou choose. ;or e6ample?suppose the cursor is on the h o the line ""This is a unn! e6ample.%% 8 and !ou give the command !r a non-,E)S+

    where CESK is the ES &e!. The line would now read

    ""Tr! a nonunn! e6ample.%% 8 nstext ;ollowed ! CESK? this sustitutes textor the ne6tn

    characters? starting with the one under the cursor. 2 covers the nth character when !ou egin thesustitution.

    ncwtext ;ollowed ! CESK? this changes the ne6t nwords?eginning at the cursor position? to text.Lhen !ou start? a covers the last character o the nth word to e replaced.

    n)text ;ollowed ! CESK? this replaces nlines? eginning with the current one? with text.+ !ou don%t give a numer? the entire current line is replaced.

    Stext ;ollowed ! CESK? this replaces the rest o thecurrent line (starting with the cursor position) with text.

    Notice that, except for the r and R commands, all these commands delete a fixedamount of material and then put i into insert mode. he new text you supply cancontain any number of characters or lines@@whateer you type until you press the 07-#ey.

    wo additional commands are useful here. he first is the u >undo? command. Itundoes the most recent command that changed the file you are editing. his is usefulfor correcting an editing mista#e@@if you gie the u command immediately after youma#e that mista#e. :ou cannot 66bac# up&& to an earlier change because a second uwould only undo the preious u. he other, the p >transpose? command, is actuallythe >delete@character? followed by the p >put? command. he result of p is tointerchange the character under the cursor with the one to the right of it.

  • 7/23/2019 UNIX - Naredbe Itd.

    30/60

    Movin! and Replicatin! "et

    o rearrange lines or groups of lines, use 66yan#&& and 66put&& commands3n ""!an&s%% (actuall! duplicates) ncomplete lines?

    eginning with the current one? and places them in an

    unnamed uer (a temporar! storage area).

    nw Ian&s nwords? starting at the current cursor position? and places them in the unnamed uer.

    p uts te6t rom the unnamed uer ater the current line i the uer contains ull lines? or ater the cursor position i the uer contains a partial line.

    ' wP Lrites the ile unconditionall! (even i it was

    unchanged) and >uits.

    >w Lrites out a new version o the ile? replacing the previous one? ut &eeps !ou in vi.

    >wname Lrites the new version as ile name,leaving the original ile untouched? and &eeps !ou in vi.

    >P= $uits? discarding all !our editing changes.

    >e= *iscards !our editing changes and starts editing the previous version o the ile all over again.

    0? must be terminated by the Return#ey.

  • 7/23/2019 UNIX - Naredbe Itd.

    31/60

    ,ote0If you cannot write out your file because you hae reached your66hard&& "uota, you may be able to remoe unwanted files withoutleaing i, then write out your wor#. o do this, use the followingcommands3

    >sh

    his gets you to the shell, temporarily setting aside your i editingsession. Now use

    ls -l

    to get a long@form directory listing and

    rmfiles

    to delete unneeded files and get below "uota. hen use ^dor eittoexit from the shell and come bac# to i. Now write out your edited file.

    More In%ormation a'out vi

    < free tutorial document for the i text editor,Introduction to i, is aailable from the=elp 'es#. :ou can also download the document >in 8'F format? from

    www.utexas.edu/cc/docs/cctuv?1.pdf

    For detailed information about i, see!earning the "i #ditor,by inda amb>&*eilly W pronounced 66ee@eye&&?. nand 957? systems, the DNU 05

  • 7/23/2019 UNIX - Naredbe Itd.

    32/60

    Startin! vi

    efore using i, be sure that you hae correctly identified your terminal type to theUNIX system. 9i uses information associated with your terminal type when it moesthe cursor and scrolls lines of text up and down. If you hae not yet identified the

    terminal type, as described in section 2.!, do so before calling i. If you use i withoutidentifying your terminal type, i responds 66$using open mode%Q, and displays onlyone line at a time.

    o call the i editor, use the command

    viname

    where name is the name of the file you want to create or modify. If the file alreadyexists in your wor#ing directory, i displays the first screenful and, at the bottom lineof the display, tells you how big the file is. If i can&t find a file by that name, it tellsyou the file is new.

    Unli#e some display editors, i does not automatically insert into the file eerythingthat you type. Instead, it has a command mode and an insert mode. ;hen you start upi, you are in command mode. If you gie a command that puts i into insert mode,you remain in insert mode until you press the 07- #ey to go bac# to command mode.5ost commands you type to i will not show on the screen, and they do not need the*eturn #ey to terminate them. ne exception to this is commands that begin with acolon >3?. downward and upward? oer the file. ;ithin thatwindow, you moe the cursor to the position where you want to insert, delete, orreplace text. ;hen you begin editing a file that already exists, the window is the firstscreenful, or page, of the file. he following control characters moe the window upand down3

    ^d Moves the window down hal a screenul. ^u Moves the window up hal a screenul. ^f Moves the window orward one ull screen (with a ew lines o overlap). ^& Moves the window ac&ward one ull screen.

    o redraw the current window, use ^l>lowercase 66&&?.

    o moe the cursor within the window, use any of the following3

    hQJQkQl Moves the cursor one character position let? down? up? or right? respectivel!. ,n some terminals? the arrow &e!s serve the same unction. N Moves the cursor to the eginning o the ne6t line. - Moves it to the eginning o the previous line. !eturn Same as F.

  • 7/23/2019 UNIX - Naredbe Itd.

    33/60

    * Moves the cursor to the top (highest line) o thescreen. L Moves it to the ottom (lowest line) o the screen. " Moves it to the middle line on the screen. w Moves the cursor right? to the eginning o the ne6tword.

    & Moves it let? to the eginning o the previous word. ?(Gero) Moves it to the eginning o the current line. ( Moves it to the end o the current line.

    o moe the cursor to a position that may be outside the current window, use one ofthe following commands3

    /string!eturn Searches orward or string,centering the line containing it in the new window. + the searchreaches the end o the ile without inding the string? it ""wraps around%% to the eginning o the ile and continues searching.

    string!eturn Searches ac&ward or string,also wrapping around i stringis not etween the starting point and the eginning o the ile.

    nR Moves to line n.

    R Moves to the last line o the ile.

    he alue ofstring is 66remembered&&, and so =Return searches forward for the mostrecently named string, and Return searches bac#ward for it.

    Insertin! "et

    7eeral commands put i into insert mode. In insert mode, eerything you type isinserted into the file until you press the 07- >escape? #ey. =ere are some of the mostuseful commands to initiate insert mode3

    i Hegins inserting te6t immediatel! eore the cursor. a Hegins inserting te6t immediatel! ater the cursor. o ,pens a new line elow the current one and enters insert mode. Iou ma! t!pe an! numer o new lines. M (uppercase o) ,pens a new line aove the current one and enters insert mode.

    Deletin! "et

    In general, use the d command to delete material. he d command ta#es an argumentto describe what #ind of entity to delete, and it can be prefixed with a number toindicate the number of repetitions for this deletion. yping dand then stri#ing thespace bar deletes the character under the cursor. If you type Pd, then space, you deletefie characters@@the current one plus the next four. ther forms are3

    dw*eletes rom the cursor position through the end o the word. 5dwdeletes our words' the current one and the ne6tthree.

    dd*eletes the entire current lineJ 2dddeletes two lines.

  • 7/23/2019 UNIX - Naredbe Itd.

    34/60

    o simply delete the character under the cursor, you can also type . here is also a Dcommand >capital '?. It deletes the rest of the current line, beginning with thecharacter under the cursor.

    Alterin! Eistin! "et

    o replace existing text with new text, you could simply use an appropriate dcommand, then insert new material at the same point. =ere are some other commandsthat replace existing text with new text3

    r ;ollowed ! a single character? this replaces thecharacter under the cursor with the new character. ;or e6ample?rs replaces whatever is under the cursor with an ""s%%.

    !text ;ollowed ! the ES &e!? this acts as i !ou had given a se>uence o rcommands? one or each character o

    the new te6t. That is? it is a oneorone character replacement o an! length !ou choose. ;or e6ample?suppose the cursor is on the h o the line ""This is a unn! e6ample.%% 8 and !ou give the command !r a non-,E)S+

    where CESK is the ES &e!. The line would now read

    ""Tr! a nonunn! e6ample.%%

    8 nstext ;ollowed ! CESK? this sustitutes textor the ne6tn

    characters? starting with the one under the cursor. 2 covers the nth character when !ou egin thesustitution.

    ncwtext ;ollowed ! CESK? this changes the ne6t nwords?eginning at the cursor position? to text.Lhen !ou start? a covers the last character o the nth word to e replaced.

    n)text ;ollowed ! CESK? this replaces nlines? eginning with the current one? with text.+ !ou don%t give a numer? the entire current line is replaced.

    Stext ;ollowed ! CESK? this replaces the rest o thecurrent line (starting with the cursor position) with text.

    Notice that, except for the r and R commands, all these commands delete a fixedamount of material and then put i into insert mode. he new text you supply cancontain any number of characters or lines@@whateer you type until you press the 07-#ey.

  • 7/23/2019 UNIX - Naredbe Itd.

    35/60

    wo additional commands are useful here. he first is the u >undo? command. Itundoes the most recent command that changed the file you are editing. his is usefulfor correcting an editing mista#e@@if you gie the u command immediately after youma#e that mista#e. :ou cannot 66bac# up&& to an earlier change because a second uwould only undo the preious u. he other, the p >transpose? command, is actually

    the >delete@character? followed by the p >put? command. he result of p is tointerchange the character under the cursor with the one to the right of it.

    Movin! and Replicatin! "et

    o rearrange lines or groups of lines, use 66yan#&& and 66put&& commands3n ""!an&s%% (actuall! duplicates) ncomplete lines?

    eginning with the current one? and places them in anunnamed uer (a temporar! storage area).

    nw Ian&s nwords? starting at the current cursor

    position? and places them in the unnamed uer.

    p uts te6t rom the unnamed uer ater the current line i the uer contains ull lines? or ater the cursor position i the uer contains a partial line.

    ' wP Lrites the ile unconditionall! (even i it was unchanged) and >uits.

    >w Lrites out a new version o the ile? replacing the previous one? ut &eeps !ou in vi.

    >wname

  • 7/23/2019 UNIX - Naredbe Itd.

    36/60

    Lrites the new version as ile name,leaving the original ile untouched? and &eeps !ou in vi.

    >P= $uits? discarding all !our editing changes.

    >e= *iscards !our editing changes and starts editing the

    previous version o the ile all over again.0? must be terminated by the Return#ey.

    ,ote0If you cannot write out your file because you hae reached your66hard&& "uota, you may be able to remoe unwanted files withoutleaing i, then write out your wor#. o do this, use the followingcommands3

    >sh

    his gets you to the shell, temporarily setting aside your i editing

    session. Now use

    ls -l

    to get a long@form directory listing and

    rmfiles

    to delete unneeded files and get below "uota. hen use ^dor eittoexit from the shell and come bac# to i. Now write out your edited file.

    More In%ormation a'out vi

    < free tutorial document for the i text editor,Introduction to i, is aailable from the=elp 'es#. :ou can also download the document >in 8'F format? from

    www.utexas.edu/cc/docs/cctuv?1.pdf

    For detailed information about i, see!earning the "i #ditor,by inda amb>&*eilly W

  • 7/23/2019 UNIX - Naredbe Itd.

    37/60

    :ou can also use the mail software on UNIX systems. ;hen you receie the message66:ou hae mail&& or 66:ou hae new mail&&, it means another user has sent you amessage.

    n see section 2.!?. hen type

    pine

    :ou should see a display li#e the following3+7E .N M2+7 ME7/ ;older'+7H,O Messages

    3E

  • 7/23/2019 UNIX - Naredbe Itd.

    38/60

    Readin! Mail

    =ere is what you might see if you type i on 8ine&s main menu to see what&s in yourINX3

    +7E .N ;,preious? and n >next?commands to highlight its header. hen press Returnor gie the command v to iewits contents.

    ;hen you iew any particular message, the bottom of that screen will displaydifferent options, so that you can handle the message as you wish3 delete it, reply to it,forwared it, print it, etc. If you sae a message, 8ine as#s for the name of anotherfolder to put it in. hen, when you "uit, 8ine deletes it from the folder named INX.

  • 7/23/2019 UNIX - Naredbe Itd.

    39/60

    Message Te6t

    8P Pet 3elp 8 ancel 8R Rich 3dr 8I rvg-Top 8 ut also on --;F? as well as to 66ones&& on the U7 system, type

    csa&12$Q [email protected]

    If you regularly send messages to the same group of people, you can define a singlename to represent all of them, and put that name in your 8ine address boo#. Useoption < from 8ine&s main menu. hen type a "uestion mar# and follow theinstructions displayed there to set up an address boo#. hen when you are at the 66o3&&line, ust tell 8ine to go to your address boo# and select the name that refers to thatgroup. 8ine will fill in all the addressees on the 66o3&& line.

    ,ote0o send mail to the

  • 7/23/2019 UNIX - Naredbe Itd.

    40/60

    . Runnin! (ro!rams on U,I

    his chapter describes the general procedures needed to compile, load, lin#, andexecute programs written in Fortran //, -, and 8ascal. o be able to use thesecompilers on the --;F system, you must include in your search path the twodirectories

    -usr-ccs-in -opt-S/7Lspro-in

    o run programs written in other languages, see the appropriate man pages.

    2ortran KK (ro!rams

    he Fortran // compiler on UNIX is f//, which is called with the commandf77[options] file ...

    wherefile is the name of your Fortran source file. If the last two characters of thesource filename are 66.f&& or 66.F&&, the file is treated as a Fortran // program. 7ourcefiles with the 66.F&& suffix are passed through the - language preprocessor before f//compiles them.

    In the simplest form of the %KK command, when no options are specified, the sourcefile is compiled and the obect program is written to a file with the same name butwith the 66.F&&, or 66.f&& suffix replaced by 66.o&&. his obect file is then loaded into an

    executable file named a.out. If you hae specified more than one filename, all of the66.o&& files are loaded, in order, into a.out. o execute the program, simply type

    a.out

    as a command.

    =ere are some of the most useful %KKcommand options3

    -c

    7uppresses loading into a.out and merely compiles@@that is, creates

    66.o&& files. >Normally, the 66.o&& files would be deleted after a.out iscreated.? hese 66.o&& files can be used as arguments to subse"uent %KKcommands.

    -!

    Denerates a special symbol table that can be used by debuggingprograms >described in chapter E?.

    -ooutfile

    http://www.utexas.edu/cc/docs/ccug1/chap8.htmlhttp://www.utexas.edu/cc/docs/ccug1/chap8.html
  • 7/23/2019 UNIX - Naredbe Itd.

    41/60

    Names your executable file outfile instead of a.out. Note that wheneera compiler ma#es a new file a.out, it destroys any preious one.

    -U

    8reents uppercase characters from being conerted to lowercase ones.

    For a complete list of options, see the %KK man page. >n

  • 7/23/2019 UNIX - Naredbe Itd.

    42/60

    he pc compiler treats any file whose final two characters are 66.p&& as a 8ascal sourceprogram. ;hen 8ascal compiles a source program, which may exist as one or seeral66.p&& files, it writes obect code to files with the same name but with 66.p&& replaced by66.o&&. hese obect files are then loaded, in order, into an executable file whose nameis a.out. o execute the program, simply type

    a.outas a command.

    =ere are some useful pc command options3

    -c

    7uppresses loading of executable file a.out and compiles only,producing 66.o&& files, which can be used as input to a later pccommand.

    -!

    Denerates output to be used by debugging programs >seechapter E?.

    -ooutfile

    Names the executable file outfile instead of a.out.

    -s

    >n --;F only? Issues warning messages if any nonstandard 8ascalconstructs are encountered.

    -std

    >n U7 only? Issues warning messages if any nonstandard 8ascalconstructs are encountered.

    For a complete list of options, see the pc man page. >n

  • 7/23/2019 UNIX - Naredbe Itd.

    43/60

    cc -c testrun.c %B error -P

    he BN here assures that both standard output and error output from cc will be pipedto the errorprogram. he -; option tells the errorprogram to "uery you before

    putting error messages into the file testrun.c. Its output might loo# li#e this3;ile ""testrun.c%% has errors.

    o these errors can e inserted into the ile. *o !ou want to preview the errors irst

    66.o&&?files.

    o execute the program under control of the debugger, do not gie 66a.out&& as acommand. Instead, use d' li#e this3

    d&x a.out

    to control its execution. he dbx program will gie you a prompt, after which you cangie commands to set and remoe brea# points, to step through execution, and to traceexecution by printing each statement before it is executed.

    If an executing program aborts, it dumps a core image, usually as a file named 66core&&.he dbx program can examine this core file to determine and display the state of the

    program when it aborted.

    For detailed information, see

    man d&x

    "ools %or Maintainin! Lar!e (ro!rams

    If you write large programs that re"uire libraries of routines, or programs that consistof many files, there are UNIX tools to help you maintain them and #eep trac# of

    modifications.

  • 7/23/2019 UNIX - Naredbe Itd.

    44/60

    he ar command maintains groups of files combined into a single archie file. heranli' command conerts archies to random libraries for easier loading by theloader. n UNIX systems running 7olaris, use the lorder command instead.

    he ma$eprogram is useful for maintaining and updating groups of programs in

    parallel.

    he sccsprogram proides mechanisms for trac#ing reisions so that you can reertto an earlier ersion of a program or maintain multiple ersions.

    For more information, see

    man sccs

    . )ter Use%ul Commands

    Settin! Spendin! Limits and Monitorin! 6our Car!es

    0ach user has a default limit for expenditures >such as pages sent to a printer, or dailycharges for elesys?. 0ach night, information about that day&s computer use istransmitted to the central accounting system from eery or exceed? either thelimit, the accounting system will change your status so that the next day you cannotcontinue to use the serices. n letter 66el&& for 66list&&?3

    spend -l

    his lists your accrued charges >as of the preious night&s accounting update?.

    IF? user can use the spendcommand to set an annual ceiling on computer charges. For an IF user, these are themaximum out@of@poc#et expenses that can accrue oer the fiscal year >1 7eptemberthrough !1

  • 7/23/2019 UNIX - Naredbe Itd.

    45/60

    -omputer account sponsors can use a -u flag on the spend command to set limits forindiidual user numbers under the computer account. For example, a sponsor in theastrology department could set limits for the user 7

  • 7/23/2019 UNIX - Naredbe Itd.

    46/60

    #rep[options] expression [file] ...or f#rep[options] [string] [file] ...

    If you gie no filenames, !rep and %!rep search standard input >your terminal?, and sothey can be used at the end of a pipeline of commands >seechapter (?. he !rep

    program expands special characters in the gien expression. he %!repprogram doesnot expand any characters, but searches for exact matches of the character string youspecify. Normally, both !rep and %!rep will search the files you specify and produce alist, on standard output, of eery line containing the text string matching the string orexpression you specified.

    he !rep command can expand special characters to find matches in much the waythe shell expands special characters in file and directory names. elow is a simplifiedexplanation of that expansion. he term 66special character&& here means one of theseen characters

    ; [ ] . ^ (and a delimiter >such as apostrophe? used to mar# the beginning and end of anexpression. he delimiters are re"uired if the expression contains any blan#s orspecial characters, and they can be used een if the expression does not contain suchcharacters.

  • 7/23/2019 UNIX - Naredbe Itd.

    47/60

    he %!rep command does none of this expansion4 howeer, you can search for morethan one string of characters with a single %!rep command. o do this, place the

    possible strings, one per line, in a file. hen use the option -%fileinstead of the stringoption when you call %!rep, li#e this3

    f#rep -f list intro.draftIf file 66list&& contains

    manual. manuals manuall!

    %!rep would find all lines in intro.draft that contain 66manual.&& or 66manuals&& or66manually&&.

    =ere are some useful options to both !rep and %!rep0

    -i +gnores case? so that uppercase and lowercase characters match each other.

    -n *ispla!s the line numer with each line containing a match. -l *ispla!s onl! the names o iles that contain matching lines? ut not the lines themselves. This is useul i !ou are searching through a set o iles to see which o them contain a particular pattern. -v *ispla!s lines that don%t match a given pattern.

    Comparin! Contents o% 2iles

    he di%%program is useful in determining how the contents of two files or directoriesdiffer. he simplest way to use it is

    diffoldfile newfile

    his produces, on standard output, a list of lines that must be changed >c?, appended>a?, or deleted >d? to ma#e the first file match the second. ines from the first file are

    prefixed by 66M&& and lines from the second are prefixed by 66&&.

    If you only want to determine IF two files differ, and not =; they differ, you canuse cmp3

    cmpfile1 file2

    he cmpprogram merely notifies you if the files don&t match, stopping its comparisonafter it finds the first difference.

    "rans%errin! 2iles "o and 2rom )ter Computer S#stems

    he F8 >File ransfer 8rotocol? program moes files from one computer to another.o use F8, you call it, open a connection to the remote computer >remote host? and,within F8, log in on that remote host. he remote host will be running its ownersion of F8 as well, with the local F8 >called the user interface? tal#ing to theremote F8 >the serer?. ;ithin this F8 enironment, you can list the files in yourremote directory, ma#e local copies of remote files, ma#e remote copies of local files,and delete remote files.

  • 7/23/2019 UNIX - Naredbe Itd.

    48/60

    ,ote0It is generally not a good idea to transfer binary executable filesfrom one computer architecture to another. -ompiled programs willalmost certainly not run on the receiing system without recompilation,so you should transfer source files of programs instead.

    o illustrate a simple F8 session, the following example shows user csab12! loggedin on the --;F UNIX system, using F8 to get file cprog.data from U7 andnaming the --;F copy of it cdata.sun. User csab12! has the login name doe onU7. ;hat the user types is shown in boldface. 0erything else is from the local--;F F8 or, in the case of responses that begin with a number, remote U7 F8.Y tp

    tpK open uts.cc.ute6as.edu(1) onnected to uts.cc.ute6as.edu. 0 curl!.cc.ute6as.edu ;T server (,S;-1 Qersion Z.N0) read!.() 7ame (uts.cc.ute6as.edu'csa1)' Ddoe

    1 assword re>uired or Ddoe. assword' 666666() 0 /ser Ddoe logged in. tpK get cprog.data cdata.sun(W) 00 ,RT command successul. 1Z0 ,pening data connection or cprog.data (1..1W.11?NN)(Z !tes). N Transer complete. local' cdata.sun remote' cprog.data ZWW !tes received in 0.0Z seconds (1 !tes-s) tpK >uit

    1 Pood!e.1. In the opencommand, the user gae the full name of the U7 host, but in this

    instance ust 66uts&& would suffice.2. Notice that the response is from 66curly&&, a specific member of the U7

    cluster.!. he password is not actually displayed.(. he !et command has the syntaxZ. #etremotefile localfile

    he remote file is assumed to be in your login directory on the remote machine. helocal copy will be placed in your current wor#ing directory. =oweer, you can gie a

    pathname as part of either remotefile or localfile to transfer between different remote

    directories and local directories to which you hae appropriate access.

    =ad user csab12! wanted to send, instead of !et, a file, the command would be

    putlocalfile remotefile

    esides the man page, F8 has internal help that proides short explanations of allaailable commands. In response to the ftp prompt, type

    help

    wo particularly useful commands are m!et and mput which enable you to specifywildcards to get or put multiple files. he F8 program prompts you for eachmatching file before it transfers it. For example, suppose you hae fie files that end

    in .txt on a remote machine, in a large directory, and you want to get only two of thosefie files. he files are3

  • 7/23/2019 UNIX - Naredbe Itd.

    49/60

    *ocument9list.t6t ile1.t6t ile.t6t m!ile.t6t notitle.t6t

    hat part of your F8 session might loo# li#e this3

    tpK mget [.t6t mget *ocument9list.t6t n mget ile1.t6t n mget ile.t6t ! 00 ,RT command successul. 1Z0 ,pening H+72RI mode data connection or ile.t6t(1..W.?:W) (ZZ !tes). N Transer complete. ZZ !tes received in 0.0 seconds (0.011 !tes-s) mget m!ile.t6t n mget notitle.t6t ! 00 ,RT command successul. 1Z0 ,pening H+72RI mode data connection or notitle.t6t

    (1..W.?:N) (: !tes). N Transer complete. : !tes received in 0.0NZ seconds (0.01Z !tes-s) tpK

    he QF8 8oc#et *eference istQ, describes basic F8 commands. It is online atwww.cc.utexas.edu/cc/docs/ccrl$$.html

    Readin! USE,E" ,e/s

    7eeral thousand electronic bulletin boards, called U70N0 newsgroups, containdiscussions of topics ranging from specific sciences to computer languages torecreational pursuits. 7ee

    www.cc.utexas.edu/cc/usenet/

    for more information about U70N0 news.

    < file in your login directory, named .newsrc, #eeps trac# of all the newsgroup namesand which messages in each group you hae already seen. o read any of thesenewsgroups, use a news@reading program. ne such program is called trn. he trn

    program examines your .newsrc file and displays unread articles in the same way thatmore displays a file@@one screenful at a time. >e sure your terminal type is definedcorrectly@@see chapter 2.? ;hen you first run trn you will be 66subscribed to&& anewsgroup named news.announce.newusers, which contains useful information and

    guidelines for what is called 66neti"uette&&@@common courtesy to use in postingmessages.

    he trnprogram has many more options than can be discussed here@@ selectingarticles by subect matter, subscribing and unsubscribing to newsgroups, saingarticles, and searching for patterns within an article. :ou can also reply to the senderof an article or post a follow@up message. For a complete description, see the trn man

    page.

    o post your own new message to a newsgroup, use the (ne/sprogram. >Notice thecapital 668&&.? It prompts you for necessary information.

    http://www.utexas.edu/cc/docs/ccrl33.htmlhttp://www.utexas.edu/cc/usenet/http://www.utexas.edu/cc/docs/ccug1/chap2.htmlhttp://www.utexas.edu/cc/docs/ccug1/chap2.htmlhttp://www.utexas.edu/cc/docs/ccrl33.htmlhttp://www.utexas.edu/cc/usenet/http://www.utexas.edu/cc/docs/ccug1/chap2.html
  • 7/23/2019 UNIX - Naredbe Itd.

    50/60

  • 7/23/2019 UNIX - Naredbe Itd.

    51/60

    Y ps u m!name #

  • 7/23/2019 UNIX - Naredbe Itd.

    52/60

    < shell script is simply a file containing shell commands that you can execute li#ethis3

    shfilename [arg1 arg2 ... argn]

    < shell script may also be executed by name if the file containing the shell commandshas read and execute permission >seechapter )?. If file 66doRit&& contains the shell

    commands and has such permissions, then the preious example is e"uialent to3doand with thecorrect read and execute permissions?, you could then count the number of filessimply by typing3

    countf

  • 7/23/2019 UNIX - Naredbe Itd.

    53/60

    4is the exit status of the program most recently executed in the shell script. Its alueis B for successful completion. his ariable is useful for error handling >see section1B.+?.

    44is the process id of the executing shell and is useful for creating uni"ue filenames.

    For example,

    cat (1 (2 ++ tempfile.((

    concatenates the files passed as parameters 1 and 2, appending them to a file calledtempfile.!12+( >assuming the process id is !12+(?.

    2lo/ Control

    5ost programming languages proide constructs for looping and for testingconditions to #now when to stop looping. he shell proides seeral such flow controlconstructs, including i%, %or, and /ile.

    i%

    he i% command performs a conditional branch. It ta#es the form

    ifcommand-list1then

    command-list2 else command-list fi

    < command%list is one or more commands. :ou can put more than one command on aline, but if you do so, separate them by semicolons. If the last command of command%list& has exit status B, then command%list is executed. ut if the exit status isnonCero, then command%list( is executed.

    %or

    he %or command proides a looping construct of the form

    forshell-!ariableinword-list docommand-list done

    he shell ariable is set to the first word in word%list and then command%list isexecuted. he shell ariable is then set to the next word in word%list and the processcontinues until word%list is exhausted. < common use of %or@loops is to performseeral commands on all >or a subset? of the files in your directory. For example, to

    print all the files in your directory, you could usefor i in

    do echo printin# file (i lpr (i done

    In this case, S would expand to a list of all filenames in your directory, i would be setto each filename in turn, and 4iwould then substitute the filename for i>in the eco

    and lprcommands?.

  • 7/23/2019 UNIX - Naredbe Itd.

    54/60

    /ile

    he /ile command proides a slightly different looping construct3

    whilecommand-list1

    do command-list2 done

    ;hile the exit status of the last command in command%list& is B, command%list isexecuted.

    "est

    he test command can be used to compare two integers, to test if a file exists or isreadable, to determine if two strings are e"ual, or to test seeral other conditions. Forexample, to test whether the alue of shell ariable x is e"ual to ), use

    test (x -eP 3

    If 4 is e"ual to ), test returns true.

    ther useful tests include

    test -sfile (true i ile e6ists and has a siGe larger than0) test -wfile (true i ile e6ists and is writale) test -Kstring (true i the length o string is 0) teststring1=:string2 (true i string1and string2are not identical)

    he test command is often used with the flow@control constructs described aboe.=ere is an example of test used with the i% command3

    if test G(1G : GG (or if [G(1G : GG]) then echo usa#e> mname xxxx exit 1 fi

    his tests to see if the command line contains an argument >41?. If it does not >41isnull?, then ecoprints a message.

    < complete list of test operators can be found in the man page for test.

    Error Handlin!

    0ach time a program is executed from within a shell script, a alue is returned toindicate whether the program ran successfully or not. In most cases, a alue of Cero isreturned on successful execution, and a nonCero number is returned if the programencountered an error. his exit status is aailable in the shell ariable 4.

    For example,

    #rep (1 phonelist if test ( -ne ? then echo V have no phone num&er for (1

    fi

  • 7/23/2019 UNIX - Naredbe Itd.

    55/60

    will run a program >!rep? and examine the exit status to determine if the program ranproperly.

    "raps

    7ome signals cause shell scripts to terminate. he most common one is the interruptsignal Jc typed while a script is running. 7ometimes a shell script will need to dosome cleanup, such as deleting temporary files, before exiting. he trap commandcan be used either to ignore signals or to catch them to perform special processing.For example, to delete all files called 66tmp.S&& before "uitting when an interrupt signalis generated, use the command

    trap Irm tmp.A exitI 2

    he interrupt signal is signal 2, and two commands will be executed when an interruptis receied >rm tmp. and eit?. :ou can ma#e a shell script continue to run afterlogout by haing it ignore the hangup signal >signal 1?. he command

    trap I I 1

    allows shell procedures to continue after a hangup >logout? signal.

    Command Su'stitution

    < useful capability in shell programming is to assign the output from a program to ashell ariable or use it as a pattern in another command. his is done by enclosing the

    program call between accent grae >6? characters. For example, the commandwhere:CpwdC

    will assign the string describing the current wor#ing directory >the results of the p/dcommand? to the shell ariable /ere. =ere is a more complicated example3

    for i in Cls -t .fC

    do f77 (i a.out +output cat (i output % lpr -'(1 rm a.out output done

    In this case, the shell script executes a series of commands for each file that ends with66.f&& >all Fortran programs?. he Vls -t .%V is executed and expands into all filenamesending with 66.f&&, sorted by time, most recent to oldest. 0ach is compiled andexecuted. hen the source file and output file are sent to the printer identified by thefirst argument >1? passed to the shell script. hen these files are deleted.

    I=) Redirection

    esides the IA redirection already described, there are a few additional forms ofredirection. Under the ourne shell, standard input is also associated with filedescriptor B, standard output with file descriptor 1, and standard error output with filedescriptor 2. 7o both file and 1file redirect standard output to file, and 2fileredirects standard error output to file.

    o merge standard output >file descriptor 1? and standard error output >file descriptor2?, then redirect them to another file, use this notation3

    command+file2+B1

  • 7/23/2019 UNIX - Naredbe Itd.

    56/60

  • 7/23/2019 UNIX - Naredbe Itd.

    57/60

    Communicationsrom list senders o mailMail send and receive mailmesg permit or den! terminal messages and tal& re>uestspine send and receive mail (easiest or new users)tal& tal& to another loggedin user (ull screen)

    write write to another loggedin user

    (ro!rammin! "oolsar archive and lirar! maintaineras assemler? speciic to each machine architectureaw& pattern scanning and processing language-in-time time a commandcc compiler (6lc on 2*S)cronta maintain periodic tas&scsh shell command interpreterd6 sourcelevel deugging program:: ;ortran compiler (6l on 2*S)gd P7/ roDect deugger

    gpro displa! proile o called routines&ill &ill a processld the /7+O loaderle6 generate le6ical anal!sis programslint chec& source codema&e maintain large programsmaple s!molic mathematics programnice run a command at low priorit! (see \man nice\ or \man csh\)nohup run a command immune to hangupspc ascal compiler (6lp on 2*S)perl opular script interpreterpro displa! proile dataranli convert archives to random liraries

    sh Hourne shell command interpreter!acc generate input parsing programs

    Documentationapropos locate commands ! &e!word loo&upino start the +noE6plorer program (2*S onl!)man ind manual inormation aout commands-usr-in-O11-d6oo& start the Hoo&Reader program (/TS onl!)whatis descrie what a command iswhereis locate source? inar!? or man page or a program

    Editorsed lineoriented te6t editoremacs screenoriented te6t editore6 lineoriented te6t editorpico simple? screenoriented te6t editor (easiest or new users)sed streamoriented te6t editorvi ullscreen te6t editorvim ullscreen te6t editor (\viimproved\)

    2ile and Director# Mana!ementcd change wor&ing director!chmod change the protection o a ile or director!cmp compare two ilescomm select-reDect lines common to two sorted ilescompress compress a ilecp cop! ilescr!pt encr!pt-decr!pt iles (L; onl!)

  • 7/23/2019 UNIX - Naredbe Itd.

    58/60

    di compare the contents o two 2S++ ilesile determine ile t!pegrep search a ile or a patternln ma&e a lin& to a ilels list the contents o a director!m&dir create a director!

    mv move or rename iles and directoriespwd show the ull pathname o !our wor&ing director!>uota displa! dis& usage and limitsrm delete (remove) ilesrmdir delete (remove) directoriessort sort or merge ilestee cop! input to standard output and other ilestr translate charactersumas& change deault ile protectionsuncompress restore compressed ileuni> report (or delete) repeated lines in a ilewc count lines? words? and characters in a ile

    2ile Displa# and (rintin!cat show the contents o a ileJ catenate ilesold old long lines to it output devicehead show irst ew lines o a ilelp> e6amine the printer spooling >ueuelpr print a ilelprm remove Dos rom the printer spooling >ueuemore displa! a ile? one screen at a timepage li&e \more\? ut prints screens top to ottompr paginate a ile or printingtail show the last part o a ileGcat displa! a compressed ile

    2ile "rans%ertp transer iles etween networ& hostsrcp transer iles etween networ&ed /7+O hostsscp secure version o rcprG receive iles using ]M,*EM protocolsG send iles using ]M,*EM protocol

    Miscellaneousalias deine s!non!m commandsch>uota change dis& >uota on 2+TS /7+O s!stemschsh change deault login shellclear clear terminal screenecho echo arguments

    learn re>uest computeraided instruction (not on L;)pm portale itmap manipulation programspopd pop the director! stac& ( shell onl!)pushd push director! on stac& ( shell onl!)script ma&e t!pescript o terminal sessionsetenv set an environment variale ( shell onl!)stt! set terminal options

    ,e/s=,et/or$snetstat show networ& status (on /TS? -usr-sin-netstat)news sumit /SE7ET news articlesrlogin login remotel! on another /7+O s!stemslogin secure version o rlogin

    tin read-post /SE7ET news articlestrn read-post /SE7ET news articles using threaded news reader

  • 7/23/2019 UNIX - Naredbe Itd.

    59/60

    rsh run shell or command on another /7+O s!stemssh secureshell version o rshtelnet run Telnet to log in to remote host

    (rocess Control

    >he following commands function under the - shell, bash, and #sh. hey do nothae separate man pages.?

    g put suspended process into ac&groundg ring process into oregroundDos list processes8! suspend process at ne6t input re>uest8G suspend current process

    Status In%ormationspend lists !eartodate 2+TS /7+O chargesdate show date and time

    d summariGe ree dis& spacedu summariGe dis& space usedenv displa! environmentinger loo& up user inormationhistor! list previousl! issued commands ( shell? ash? and &sh onl!)last indicate last login o userslp> e6amine spool >ueuemanpath show search path or man pagesprintenv print out environmentps show process statuspwd print ull pathname o wor&ing director!set set shell variales ( shell? ash? and &sh onl!)

    stt! set terminal optionsuptime show s!stem load? how long s!stem has een upw show who is on s!stem? what command each Do is e6ecutingwho show who is logged onto the s!stemwhois +nternet user name director! service

    "et (rocessin!addi create or e6tend iliographic dataase (not on /TS)chec&nr chec& nro-tro ilescol ilter reverse line eedsdiction identi! word! sentences (not on L;)dim& mar& dierences etween ilesdvips convert TeO *Q+ iles into ostScript

    e>n t!peset mathematics with troe6plain e6plain phrases ound ! diction program (not on L;)grap pic preprocessor or drawing graphs (2*S onl!)h!phen ind h!phenated words (not on L;)ind6i uild inverted inde6 or a iliograph!? ind reerences (not on /TS)ispell chec& spelling interactivel!late6 ormat te6tloo&i ind iliograph! reerences (not on /TS)macre ma&e crossreerence listing o nro-tro macro ilesnd6 create a suDectpage inde6 or a document (not on L;)ne>n ormat mathematics with nronro ormat te6t or simple displa!

    pic ma&e simple pictures or tro inputpsdit ilter tro output or 2pple

  • 7/23/2019 UNIX - Naredbe Itd.

    60/60

    pt6 ma&e permuted inde6 (not on L;)reer insert reerences rom iliographic dataases (not on /TS)roi run o iliographic dataase (not on /TS)sorti sort iliographic dataase (not on /TS)spell ind spelling errorsst!le anal!Ge surace characteristics o a document (not on L;)

    tl ormat tales or nro-trote6 ormat te6ttpic convert pic source iles into TeO commands (not on /TS)tro ormat te6t