Useful UNIX Commands

Embed Size (px)

Citation preview

  • 8/8/2019 Useful UNIX Commands

    1/25

    Useful UNIX Commands

    Useful UNIX Commands

    The following is a list of some of the more important and useful commands in Unix (specific to HPUX)

    Remember that the man command can be used to find out the specific usage of any of these.

    Essentials

    logout- use this command when you are done, always

    man - use the command `man command'to learn about a command.

    Files and Directories

    cd- change directory

    pwd- print working directory (the directory you are in)

    rmdir- remove directory (the directory must be empty)

    mkdir- make a new directory

    rm - remove a file or directory ls - list files

    cp - copy a file

    mv - move a file (destroys original)

    less - view a text file

    cat- prints the contents of a file on the screen

    touch - create an empty file

    gzip and gunzip - compression and decompression

    tar- Tape Archive. Now used to store directory trees as a single file for easy transfer. See the -xvf

    and -cvf options in the man page

    uudecode and uuencode decode and encode binary files as text files for transfers

    System Status

    date - displays the current date and time

    du - displays amount of disk space in 512byte blocks ('du -s' gives the summary for a directory)

    quota -v - displays disk limits and amount currently in use

    ps - display running processes ('ps -ef | grep username' gives all the processes owned by aparticular user)

    who - display who is on the machine and where they are connected from

    w - display who is on and what they are doing

    who - display who is on and where they are on from

    jobs - display the jobs you own

    uptime - display time, number of users, and load averages

    loads - a local script to show the loads on all the HP700s

    renice - alters priority of a running process. You should renice long simulations so you don't hog

    processor cycles.

    Networking

    ssh - open an encrypted connection with a host

    telnet- open a remote session with host

    rlogin - open a remote session with host

  • 8/8/2019 Useful UNIX Commands

    2/25

    ftp - File Transfer Protocol: send and receive files betweem machines

    ping- check to make sure a remote machine is reachable

    finger- show information about a person on a system or whoever is on the remote system WWW

    version

    Editors and Text Processors

    vi - Visual Editor. Great stuff

    pico - Easy to use editor

    grep - searches a file for a pattern

    a2ps - (not currently availible) allows the formatting of text into a multi-columned format

    Printing

    Please seethe printing one-pagerfor details about printing.

    lp - print the specified file. Common usage: 'lp -dhpps file.ps'

    lpstat- tells you infomation about current print jobs

    cancel- cancel a print job. Common usage: 'cancel hpps-###'

    That should be a good start on the commands that you need. Take a look at the software available on the

    700s as well. Remember, if you don't know, ask questions. Most people here in ECE are willing to help

    other people.

    Common UNIX Commands

    This document presents a brief description of commonly used UNIX commands. The list is a small subset

    of the available commands and utilities. For more information on these commands and others not listed

    here, consult the online manual pages (see themancommand) which are accessible from WWW through

    ourman pages gatewayor talk to a member of the Informatics Core staff.Note: Enter the commands below exactly as shown (including spaces and upper- or lowercase). Arguments

    or parameters to the commands are shown in italics and should be replaced with your own values at the

    time that you execute the command (e.g. the name of a file is an argument to thecat command rather than

    the word,file).

    aliasalias-termcommand-string

    The alias built-in shell command allows the entering of shorter or easy-to-remember names to

    execute longer or hard-to-remember commands. The command is entered to set alias-term equalto command-string. Ifcommand-stringhas spaces in it, single quotes should be around the string.For example, entering alias dir 'ls -al' will allow ls -al to be executed whenever the dir command

    is entered (thus easing the transition to UNIX for the MS-DOS users). Each user can put these

    alias commands in their.cshrc file to have the aliases automatically set each time the user logs in.

    Entering alias by itself will list all the aliases currently set for the user.

    catfile

    The cat command displays the contents of the file named byfile. If the file is large, all but the last

    screenfull of lines will scroll off the screen too quickly to read. To display the file a screenful at a

    time, use themore command.

    http://eecs.oregonstate.edu/comp/doc/one_pagers/printing.htmlhttp://eecs.oregonstate.edu/comp/doc/one_pagers/printing.htmlhttp://eecs.oregonstate.edu/comp/doc/one_pagers/printing.htmlhttp://web.nwe.ufl.edu/writing/tools/unix/#manhttp://web.nwe.ufl.edu/writing/tools/unix/#manhttp://web.nwe.ufl.edu/writing/tools/unix/#manhttp://web.nwe.ufl.edu/cgi-bin/man2htmlhttp://web.nwe.ufl.edu/cgi-bin/man2htmlhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#InformaticsCorehttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#InformaticsCorehttp://web.nwe.ufl.edu/writing/tools/unix/#cathttp://web.nwe.ufl.edu/writing/tools/unix/#cathttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#cshrchttp://web.nwe.ufl.edu/writing/tools/unix/#morehttp://web.nwe.ufl.edu/writing/tools/unix/#morehttp://eecs.oregonstate.edu/comp/doc/one_pagers/printing.htmlhttp://web.nwe.ufl.edu/writing/tools/unix/#manhttp://web.nwe.ufl.edu/cgi-bin/man2htmlhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#InformaticsCorehttp://web.nwe.ufl.edu/writing/tools/unix/#cathttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#cshrchttp://web.nwe.ufl.edu/writing/tools/unix/#more
  • 8/8/2019 Useful UNIX Commands

    3/25

    chdirdirectory

    cddirectory

    The chdir command moves you (changes yourcurrent working directory) to directory. Entering

    cd without the directory argument will move you to yourhome directory.

    Examples:cd /usr/hgp

    moves you to the hgp directory inside of the usr directory.cd ..

    moves you to theparent directory of your current directory.

    chmodpermissionspath

    The chmod command changes the access permission associated with a file or directory ("file" will

    be used here to refer to either a file or a directory).

    Each file has three types of access: read (r), write (w) and execute (x). In als -al file listing, theabbreviations appear in the columns on the left. To see the contents of a file, the file must have

    read (r) permission. To change the contents of a file (e.g. saving changes after editing), write (r)

    permission must be enabled. To execute a command by entering the name at the UNIX prompt,

    the file must have execute (x) permission. To access a directory, the execute (x) permission must

    be granted for that directory. If a given type of access is not permitted, it will show up as a dash (-)

    rather than r, w or x in the ls -al listing.

    The access to a file can be controlled separately for three sets of users: the owner of the file (u), a

    limited group of users (g), and everyone on the system (o). In a ls -al file listing, the first threecolumns (starting in column two of the listing) are the r, w and x access allowed for the owner, the

    second three are the access allowed for the group and the third three are the access allowed foreveryone else.

    Permissions can be specified in numeric format or using the abbreviations above. For the numeric

    format, three numbers are specified where each number represents the access granted for one of

    the three sets of users. Each permission number is determined by adding up the value associated

    with each type of access: r = 4, w = 2 and x = 1. For example, the value 7 grants all access, the

    value 5 grants only read and execute access but not write access and the value 0 does not allow

    any access to the file. The numeric access specification is an absolute one; all three types of access

    for all three sets of users are reset according to the newpermissions.Examples:

    chmod 640 .cshrc

    grants read and write permission (6) to the owner of the file, read-only permission to the group,and no permissions for everyone else. The would appear in a file listing as rw-r-----.

    chmod 777 .

    grants all access to the owner, group, and everyone for the current working directory.

    Thepermissions can also be specified using abbreviations rather than numbers. Using this method,

    some of the permissions can be changed without affecting others. Thepermissions format is . The + adds the access indicated to the file without affecting the other

    permissions. The - removes the access from the file.

    Examples:

    chmod u+rw report

    adds read and write permission to the file, report, for the owner of the file. Access for the group

    and everyone is unchanged.

    chmod +x somecommand

    adds execute permission to the file, somecommand, for all three sets of users.chmod go-rwx private.file

    removes all access to the file, private.file, for the group and everyone and leaves the owner'saccess unchanged.

    chownusernamepath

    The chown command changes the ownership of the file or directory,path, to user, username. Both

    the user-ownership and the group-ownership may be changed at once by specifying user.group for

    the username parameter. One must have root privilages to do this so this command will not be too

    useful for most users. If you really want to own someone else's file that you have read-access to,

    make a copy of the file using the command, cp.

    http://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#homedirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#parentdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/#lshttp://web.nwe.ufl.edu/writing/tools/unix/#lshttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#UNIXprompthttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#UNIXprompthttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/#cphttp://web.nwe.ufl.edu/writing/tools/unix/#cphttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#homedirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#parentdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/#lshttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#UNIXprompthttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/#cp
  • 8/8/2019 Useful UNIX Commands

    4/25

    cpfile1 file2

    The cp command creates an identical copy of the file,file1, and names the copy,file2. Note that

    the ownership offile2 will be set to whoever does the cp command.

    date

    The date command displays the current date and time. Use date -u to see the time in GreenwichMean Time (GMT), universal time.

    difffile1file2The diffcommand compares the contents of two text files and displays the differences. The lines

    preceded with < are fromfile1. The lines preceded by > are fromfile2. Each section of differences

    is separated by ---.

    enscripttextfile

    The enscript command converts the file, textfile, (that you might otherwise print with lpr) to

    Postscript and then prints it. More importantly, enscript allows the printing of two text pagesreduced onto one piece of paper with page numbers and a title. For example, enscript -2rG

    lots.of.docs prints the file, lots.of.docs, in landscape mode, two pages per printout, with fancy

    headers.

    exit

    The exit command terminates the current UNIXshell. If you started this UNIX session (shell)

    with either therlogin,su command from within another session, exit returns you to your previous

    session. If not, exit usually just closes your window (either an xterm window or terminal program

    window) or returns you to a login: prompt.fingername@address

    The finger command displays information about user accounts with names (usernames or propernames) matching name on the machine identified by address. The argument name may be a

    known username or a first or last proper name without any spaces although this varies from

    machine to machine. When fingering @med.umich.edu, first and last name separated by a period

    may be used, e.g. finger [email protected].

    The finger command may not work if the remote machine is not a UNIX machine (although most

    multi-user machines have finger capability these days). If only the @address portion of the

    argument is used, all of the users currently logged into the remote machine may be displayed. If no

    argument is specified, all of the users currently logged into your machine are shown (see also thewhocommand).

    An electronic mail address can often be verified or determined using the finger command. For

    example, finger [email protected] returns a list of all Johns, Johnsons, and other variationsin the UMMC network. finger [email protected] gives all the people with an a in their

    first name and Smith in their last name.

    greppatternfile

    The grep command searches one or more files, specified byfile, for the text string specified by

    pattern. For example, grep 'dna' seqfile1 will list all lines found in the file, seqfile1, whichcontain the text "dna". Grep is usually used to search for text in several files at once, e.g. grep

    'dna' * will perform the same search on all the files in yourcurrent directory (see wildcard

    charactersfor an explanation of*).

    headfile

    tailfile

    The head and tail commands list the first (head) or last (tail) ten lines of your file. The number of

    lines listed may be varied by including -n number-of-lines option. For example, head -n 50

    report1 will list the first fifty lines of the file report1.hgppasswd

    Seepasswd.killid-number

    The kill command terminates theprocesswith the id, id-number. The process id can be

    determined with theps command. Generally, the kill command is the last method tried to

    terminate a running program. If a normal kill (a kill without any kill-level option specified before

    the id-number) does not remove the process, including the -9 option will usually annihilate it

    (unless it is azombie process -- in which case it doesn't exist so it can't be killed (confused yet?))

    e.g. kill -9 18201 is a "sure kill" of process number 18201.

    http://web.nwe.ufl.edu/writing/tools/unix/#lprhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#shellhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#shellhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#shellhttp://web.nwe.ufl.edu/writing/tools/unix/#rloginhttp://web.nwe.ufl.edu/writing/tools/unix/#rloginhttp://web.nwe.ufl.edu/writing/tools/unix/#rloginhttp://web.nwe.ufl.edu/writing/tools/unix/#telnet%3Etelnet%3C/a%3E%20or%20%20%20%20%3Ca%20href=http://web.nwe.ufl.edu/writing/tools/unix/#telnet%3Etelnet%3C/a%3E%20or%20%20%20%20%3Ca%20href=http://web.nwe.ufl.edu/writing/tools/unix/#whohttp://web.nwe.ufl.edu/writing/tools/unix/#whohttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#wildcardhttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#wildcardhttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#wildcardhttp://web.nwe.ufl.edu/writing/tools/unix/#passwdhttp://web.nwe.ufl.edu/writing/tools/unix/#passwdhttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#processhttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#processhttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#processhttp://web.nwe.ufl.edu/writing/tools/unix/#pshttp://web.nwe.ufl.edu/writing/tools/unix/#pshttp://web.nwe.ufl.edu/writing/tools/unix/#lprhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#shellhttp://web.nwe.ufl.edu/writing/tools/unix/#rloginhttp://web.nwe.ufl.edu/writing/tools/unix/#telnet%3Etelnet%3C/a%3E%20or%20%20%20%20%3Ca%20href=http://web.nwe.ufl.edu/writing/tools/unix/#whohttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#wildcardhttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#wildcardhttp://web.nwe.ufl.edu/writing/tools/unix/#passwdhttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#processhttp://web.nwe.ufl.edu/writing/tools/unix/#ps
  • 8/8/2019 Useful UNIX Commands

    5/25

    lprtextfile

    The lpr command will print the file, textfile on the default printer. A specific printer may be

    specified with the -P option. For example, lpr -Phgp2 sequence sends the file, sequence, to the

    printer named "hgp2".

    HGP UNIX Special Case: We have two UNIX printers (whose name can be specified with the-Pname option of the print commands). Printerhgp1 is in 2570 MSRB II, and hgp2 is in 2568

    MSRB II.lpq

    The lpq command displays the status of jobs (documents) in the print queue (waiting to print). The

    -Pprinteroption specifies which printer queue to check. For example, lpq -Phgp2 checks the

    status of documents waiting to print on the printer named "hgp2".

    lprmjob-number

    The lprm command removes the waiting document,job-number, from the print queue. The valueforjob-numbercan be obtained from thelpq command. If the job is to be removed from a print

    queue other than the default, the -Pprinterparameter is used to specify the print queue (just as

    withlprand lpq). Note that each user may only remove print jobs that their own print jobs.

    lspattern

    The ls command lists the files and directories in a directory. Ifpattern is the name of a file, only

    that file (orfiles ifwildcardsare used) is listed. Ifpattern is a directory name, the contents of that

    directory are listed. Ifpattern is omitted, all the files and directories in yourcurrent directory are

    listed. The output of the ls command may bepipedinto themore command to pause the listingafter each screenful of text (e.g. ls -al | more).

    Here are a few of the options for the ls command (for a complete list, see thels man page):-a

    lists allfiles in the current directory. Without this option, filenames that begin with a period (such

    as .cshrc, .login, and ..) are not shown).

    -l

    lists the filenames in longformat. This format includes the protections (changable withchmod) on

    each file and the owner of the file.

    -g

    adds thegroup ownership of the file to the information displayed with the -l option describedabove.

    -F

    highlights directories with a trailing /, executable files with a trailing * and symbolic links with atrailing @ in a listing.

    Examples:

    ls

    lists every file (except those filenames that begin with a period) in in thecurrent directory.

    ls -al /binlists all files in the /bin directory in the long format.

    ls -laFg

    lists all files in the current directory in long format (including group ownership), highlighting

    directories, executable files and symbolic links.

    mancommand

    The man command displays the standard UNIX manual page for the commandyou specify. These

    pages may be somewhat cryptic for some users but generally tell you all you would ever want to

    know about the command. You may search our man pages now through ourman pages gateway.mddir1

    mkdirdir1The mkdir command creates the directory, dir1, within yourcurrent directory (unless the

    specification ofdir1 begins with a /).

    HGP UNIX Special Case:md is analiasformkdir on our system.

    morefile1

    The more command displays the contents of the text file,file1, a screenful at a time, pausing at the

    end of each screen until the user presses one of a few special keys. When the display pauses, the

    user may press:

    http://web.nwe.ufl.edu/writing/tools/unix/#lpqhttp://web.nwe.ufl.edu/writing/tools/unix/#lpqhttp://web.nwe.ufl.edu/writing/tools/unix/#lprhttp://web.nwe.ufl.edu/writing/tools/unix/#lprhttp://web.nwe.ufl.edu/writing/tools/unix/#lprhttp://web.nwe.ufl.edu/writing/tools/unix/#lpqhttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#wildcardhttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#wildcardhttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#wildcardhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#pipehttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#pipehttp://web.nwe.ufl.edu/writing/tools/unix/#morehttp://web.nwe.ufl.edu/writing/tools/unix/#morehttp://web.nwe.ufl.edu/cgi-bin/man2html?lshttp://web.nwe.ufl.edu/cgi-bin/man2html?lshttp://web.nwe.ufl.edu/writing/tools/unix/#chmodhttp://web.nwe.ufl.edu/writing/tools/unix/#chmodhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/cgi-bin/man2htmlhttp://web.nwe.ufl.edu/cgi-bin/man2htmlhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/#aliashttp://web.nwe.ufl.edu/writing/tools/unix/#aliashttp://web.nwe.ufl.edu/writing/tools/unix/#aliashttp://web.nwe.ufl.edu/writing/tools/unix/#lpqhttp://web.nwe.ufl.edu/writing/tools/unix/#lprhttp://web.nwe.ufl.edu/writing/tools/unix/#lpqhttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#wildcardhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#pipehttp://web.nwe.ufl.edu/writing/tools/unix/#morehttp://web.nwe.ufl.edu/cgi-bin/man2html?lshttp://web.nwe.ufl.edu/writing/tools/unix/#chmodhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/cgi-bin/man2htmlhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/#alias
  • 8/8/2019 Useful UNIX Commands

    6/25

    to display to the next page of text,

    to display only one more line of text,

    / followed by a wordand the to search for that wordin the remaining

    text of the file,

    ? to see all the operations available in more,

    q orCONTROL-C to quit displaying the file and return to the command

    prompt.

    more may also be used at the end of a "pipe"to cause the output from another command to be

    paused a screen at a time. This is useful when a UNIX command produces a lot of output too fast

    for the user to see before the output scrolls off the screen. For example, thels -alcommand often

    produces long directory listings which are better viewed a screen at a time by entering ls -al |

    more.mvname1name2

    The mv command moves and/or renames the file or directory, name1. Ifname2 is an existing

    directory, name1 will be moved (not copied) into the directory, name2. Ifname2 is not an existing

    directory, name1 (whether it be a file or directory) will simply be renamed into name2. It is

    possible to move andrename name1 at the same time ifname2 is a new name withing an existing

    directory. Any file file already existing with name2 will be overwritten by the renaming or moving

    ofname1 unless mv -i is used, which asks the user for confirmation of destruction of existing files.HGP UNIX Special Cases:mv is analias formv -i on the HGP systems so using the -i option isnot necessary unless mv has been unaliased or aliased to something new.

    passwd

    hgppasswd

    The passwd command changes your UNIX login password. After entering the command passwd,

    you will be asked to enter your old password, then the new password that you want to change to,

    and then the same new password again. You are asked to enter the new password twice to assure

    that you have typed it correctly. None of the passwords you enter will be displayed on the screen

    as you type them.

    HGP UNIX Special Cases:

    The passwd command only affects your UNIX login password and does not

    change your Sybase database login password. hgppasswd allows to to remotely set your passwd on

    mendel.hgp.med.umich.edu without having to first login to that machine if you are

    currently logged into another HGP Sun workstation. Why would you want to do this?

    The passwords on mendel are copied out to all the other Suns twice a day. If you changed

    your password on any machine other than mendel using the passwd command, it will beoverwritten with your password from mendel within twelve hours, effectively reverting

    back to your old password. Therefore, any password changes must be made by running

    the passwd command while logged into mendel (to log into mendel from any other HGP

    Sun, see therlogincommand) or by using the hgppasswd command while logged into

    any other machine. Note that running hgppasswd from a machine other than mendel does

    not set your new password on your current machine immeadiately. You may additionally

    run the passwd command on the local machine to make the change immeadiately for that

    machine.

    ps

    The ps command displays a list of theprocesses currently running on the machine that you are

    logged into. If no arguments are entered with the ps command, only the "important" processes,

    that you own (i.e. that you are running) are displayed. The -a option includes processes owned by

    others in the list. The -g option includes all processes, not just "important" processes. The -u

    option provides more information for each processes than is printed by default.

    Examples (note that the dash in a ps option is not required):

    http://web.nwe.ufl.edu/writing/tools/unix/concepts.html#pipehttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#pipehttp://web.nwe.ufl.edu/writing/tools/unix/#lshttp://web.nwe.ufl.edu/writing/tools/unix/#lshttp://web.nwe.ufl.edu/writing/tools/unix/#lshttp://web.nwe.ufl.edu/writing/tools/unix/#aliashttp://web.nwe.ufl.edu/writing/tools/unix/#aliashttp://web.nwe.ufl.edu/writing/tools/unix/#rloginhttp://web.nwe.ufl.edu/writing/tools/unix/#rloginhttp://web.nwe.ufl.edu/writing/tools/unix/#rloginhttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#processhttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#processhttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#pipehttp://web.nwe.ufl.edu/writing/tools/unix/#lshttp://web.nwe.ufl.edu/writing/tools/unix/#aliashttp://web.nwe.ufl.edu/writing/tools/unix/#rloginhttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#process
  • 8/8/2019 Useful UNIX Commands

    7/25

    ps g

    List all the processes running that you own (minimal information).

    ps ug

    List all the processes running that you own (lots of information).

    ps agList all the processes running on this machine no matter who owns them.

    To terminate a process, see the kill command.pwd

    The pwd command displays the fullpathof yourcurrent working directory. In other words, it tells

    you what directory you are in.

    rloginaddress

    The rlogin command logs into another machine specified by address. The -l username option

    allows you to specify a username to attempt the remote login with. If this option is omitted, yourcurrent username is used by default. Examples:

    rlogin mendel logs you into the machine named mendel with your

    current username

    rlogin mendel -l smith logs you into the machine named mendel as user

    smith (of course, you must know smith's

    password).

    You can close the connection from the remote machine by entering the command,exit.

    rmyourfileThe rm command removes the file,yourfile, permanently from the filesystem. This cannot be

    undone so be careful when using wildcards in the file specification. Use rm -i to force user-confirmation of each file to be removed. Using rm -rsomedirwill remove the subdirectory

    somediras well as all the subdirectories and files within that subdirectory.

    HGP UNIX Special Cases:rm is an aliasforrm -i on the HGP systems so using the -i option is

    not necessary unless rm has been unaliased or aliased to something new.

    rmdirdir1

    The rmdir command deletes the empty subdirectory, dir1. To delete non-empty subdirectories,

    seerm -r.

    suusernameThe su command allows a user to assume the identity and permissions of another user, username

    (provided that the password forusername is known). The su session is ending by entering the

    command,exit.tailfile

    See head.

    telnetaddress

    See telnetas listed in the glossary for now.

    wcyourfileThe wc command counts the number of words or characters and lines in your file. If the -l option

    is used, only the number of lines is counted.

    who

    The who command displays a list of who is logged on to the system and where they are logged on

    from. See also finger.

    Unix Command Summary

    See the Unixtutorial for a leisurely, self-paced introduction on how to use the commands listed below. For

    more documentation on a command, consult a good book, or use the man pages. For example, for more

    information on grep, use the command man grep.

    Contents

    cat --- for creating and displaying short files

    http://web.nwe.ufl.edu/writing/tools/unix/#killhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#pathhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#pathhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#pathhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/#exithttp://web.nwe.ufl.edu/writing/tools/unix/#exithttp://web.nwe.ufl.edu/writing/tools/unix/#exithttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#wildcardhttp://web.nwe.ufl.edu/writing/tools/unix/#aliashttp://web.nwe.ufl.edu/writing/tools/unix/#aliashttp://web.nwe.ufl.edu/writing/tools/unix/#rmhttp://web.nwe.ufl.edu/writing/tools/unix/#rmhttp://web.nwe.ufl.edu/writing/tools/unix/#rmhttp://web.nwe.ufl.edu/writing/tools/unix/#exithttp://web.nwe.ufl.edu/writing/tools/unix/#exithttp://web.nwe.ufl.edu/writing/tools/unix/#exithttp://web.nwe.ufl.edu/writing/tools/unix/#headhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#telnethttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#telnethttp://web.nwe.ufl.edu/writing/tools/unix/#fingerhttp://www.math.utah.edu/computing/unix/unix-tutorial.htmlhttp://www.math.utah.edu/computing/unix/unix-tutorial.htmlhttp://www.math.utah.edu/computing/unix/#cathttp://web.nwe.ufl.edu/writing/tools/unix/#killhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#pathhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#currentworkingdirectoryhttp://web.nwe.ufl.edu/writing/tools/unix/#exithttp://web.nwe.ufl.edu/writing/tools/unix/concepts.html#wildcardhttp://web.nwe.ufl.edu/writing/tools/unix/#aliashttp://web.nwe.ufl.edu/writing/tools/unix/#rmhttp://web.nwe.ufl.edu/writing/tools/unix/#exithttp://web.nwe.ufl.edu/writing/tools/unix/#headhttp://web.nwe.ufl.edu/writing/tools/unix/glossary.html#telnethttp://web.nwe.ufl.edu/writing/tools/unix/#fingerhttp://www.math.utah.edu/computing/unix/unix-tutorial.htmlhttp://www.math.utah.edu/computing/unix/#cat
  • 8/8/2019 Useful UNIX Commands

    8/25

    chmod --- change permissions

    cd --- change directory

    cp --- for copying files

    date --- display date

    echo --- echo argument

    ftp --- connect to a remote machine to download or upload files

    grep --- search file head --- display first part of file

    ls --- see what files you have

    lpr--- standard print command (see alsoprint )

    more --- use to read files

    mkdir--- create directory

    mv --- for moving and renaming files

    ncftp --- especially good for downloading files via anonymousftp.

    print --- custom print command (see also lpr)

    pwd --- find out what directory you are in

    rm --- remove a file

    rmdir--- remove directory

    rsh --- remote shell setenv --- set an environment variable

    sort --- sort file

    tail --- display last part of file

    tar--- create an archive, add or extract files

    telnet --- log in to another machine

    wc --- count characters, words, lines

    cat

    This is one of the most flexible Unix commands. We can use to create, view and concatenate files. For our

    first example we create a three-item English-Spanish dictionary in a file called "dict."% cat >dict

    red rojo

    green verde

    blue azul

    %

    stands for "hold the control key down, then tap 'd'". The symbol > tells the computer that what

    is typed is to be put into the file dict. To view a file we use cat in a different way:

    % cat dict

    red rojo

    green verdeblue azul

    %If we wish to add text to an existing file we do this:

    % cat >>dict

    white blanco

    black negro

    %

    Now suppose that we have another file tmp that looks like this:

    % cat tmpcat gato

    http://www.math.utah.edu/computing/unix/#chmodhttp://www.math.utah.edu/computing/unix/#cdhttp://www.math.utah.edu/computing/unix/#cphttp://www.math.utah.edu/computing/unix/#datehttp://www.math.utah.edu/computing/unix/#echohttp://www.math.utah.edu/computing/unix/#ftphttp://www.math.utah.edu/computing/unix/#grephttp://www.math.utah.edu/computing/unix/#headhttp://www.math.utah.edu/computing/unix/#lshttp://www.math.utah.edu/computing/unix/#lprhttp://www.math.utah.edu/computing/unix/#printhttp://www.math.utah.edu/computing/unix/#morehttp://www.math.utah.edu/computing/unix/#mkdirhttp://www.math.utah.edu/computing/unix/#mvhttp://www.math.utah.edu/computing/unix/#ncftphttp://www.math.utah.edu/computing/unix/#ftphttp://www.math.utah.edu/computing/unix/#ftphttp://www.math.utah.edu/computing/unix/#ftphttp://www.math.utah.edu/computing/unix/#printhttp://www.math.utah.edu/computing/unix/#lprhttp://www.math.utah.edu/computing/unix/#pwdhttp://www.math.utah.edu/computing/unix/#rmhttp://www.math.utah.edu/computing/unix/#rmdirhttp://www.math.utah.edu/computing/unix/#rshhttp://www.math.utah.edu/computing/unix/#setenvhttp://www.math.utah.edu/computing/unix/#sorthttp://www.math.utah.edu/computing/unix/#tailhttp://www.math.utah.edu/computing/unix/#tarhttp://www.math.utah.edu/computing/unix/#telnethttp://www.math.utah.edu/computing/unix/#wchttp://www.math.utah.edu/computing/unix/#chmodhttp://www.math.utah.edu/computing/unix/#cdhttp://www.math.utah.edu/computing/unix/#cphttp://www.math.utah.edu/computing/unix/#datehttp://www.math.utah.edu/computing/unix/#echohttp://www.math.utah.edu/computing/unix/#ftphttp://www.math.utah.edu/computing/unix/#grephttp://www.math.utah.edu/computing/unix/#headhttp://www.math.utah.edu/computing/unix/#lshttp://www.math.utah.edu/computing/unix/#lprhttp://www.math.utah.edu/computing/unix/#printhttp://www.math.utah.edu/computing/unix/#morehttp://www.math.utah.edu/computing/unix/#mkdirhttp://www.math.utah.edu/computing/unix/#mvhttp://www.math.utah.edu/computing/unix/#ncftphttp://www.math.utah.edu/computing/unix/#ftphttp://www.math.utah.edu/computing/unix/#printhttp://www.math.utah.edu/computing/unix/#lprhttp://www.math.utah.edu/computing/unix/#pwdhttp://www.math.utah.edu/computing/unix/#rmhttp://www.math.utah.edu/computing/unix/#rmdirhttp://www.math.utah.edu/computing/unix/#rshhttp://www.math.utah.edu/computing/unix/#setenvhttp://www.math.utah.edu/computing/unix/#sorthttp://www.math.utah.edu/computing/unix/#tailhttp://www.math.utah.edu/computing/unix/#tarhttp://www.math.utah.edu/computing/unix/#telnethttp://www.math.utah.edu/computing/unix/#wc
  • 8/8/2019 Useful UNIX Commands

    9/25

    dog perro

    %

    Then we can join dict and tmp like this:

    % cat dict tmp >dict2

    We could check the number of lines in the new file like this:% wc -l dict2

    8The command wc counts things --- the number of characters, words, and line in a file.

    chmod

    This command is used to change the permissions of a file or directory. For example to make a file

    essay.001 readable by everyone, we do this:

    % chmod a+r essay.001

    To make a file, e.g., a shell script mycommand executable, we do this

    % chmod +x mycommand

    Now we can run mycommand as a command.

    To check the permissions of a file, use ls -l . For more information on chmod, use man chmod.

    cd

    Use cd to change directory. Usepwd to see what directory you are in.

    % cd english

    % pwd

    % /u/ma/jeremy/english

    % ls

    novel poems

    % cd novel

    % pwd

    % /u/ma/jeremy/english/novel

    % lsch1 ch2 ch3 journal scrapbook

    % cd ..% pwd

    % /u/ma/jeremy/english

    % cd poems

    % cd

    % /u/ma/jeremy

    Jeremy began in his home directory, then went to his english subdirectory. He listed this directory usingls ,found that it contained two entries, both of which happen to be diretories. He cd'd to the diretory novel, and

    found that he had gotten only as far as chapter 3 in his writing. Then he used cd .. to jump back one level. If

    had wanted to jump back one level, then go to poems he could have said cd ../poems. Finally he used cd

    with no argument to jump back to his home directory.

    cp

    Use cp to copy files or directories.

    % cp foo foo.2

    This makes a copy of the file foo.

    % cp ~/poems/jabber .

    This copies the file jabber in the directory poems to the current directory. The symbol "." stands for the

    current directory. The symbol "~" stands for the home directory.

    date

    http://www.math.utah.edu/computing/unix/#wchttp://www.math.utah.edu/computing/unix/#pwdhttp://www.math.utah.edu/computing/unix/#lshttp://www.math.utah.edu/computing/unix/#lshttp://www.math.utah.edu/computing/unix/#wchttp://www.math.utah.edu/computing/unix/#pwdhttp://www.math.utah.edu/computing/unix/#ls
  • 8/8/2019 Useful UNIX Commands

    10/25

    Use this command to check the date and time.

    % date

    Fri Jan 6 08:52:42 MST 1995

    echo

    The echo command echoes its arguments. Here are some examples:% echo thisthis

    % echo $EDITOR

    /usr/local/bin/emacs

    % echo $PRINTER

    b129lab1

    Things like PRINTER are so-called environment variables. This one stores the name of the default printer

    --- the one that print jobs will go to unless you take some action to change things. The dollar sign before an

    environment variable is needed to get the value in the variable. Try the following to verify this:

    % echo PRINTER

    PRINTER

    ftp

    Use ftp to connect to a remote machine, then upload or download files. See also: ncftp

    Example 1: We'll connect to the machine fubar.net, then change director to mystuff, then download the file

    homework11:

    % ftp solitude

    Connected to fubar.net.

    220 fubar.net FTP server (Version wu-2.4(11) Mon Apr 18 17:26:33 MDT 1994) ready.

    Name (solitude:carlson):jeremy

    331 Password required for jeremy.

    Password:

    230 User jeremy logged in.ftp> cd mystuff

    250 CWD command successful.ftp> get homework11

    ftp> quit

    Example 2: We'll connect to the machine fubar.net, then change director to mystuff, then upload the file

    collected-letters:

    % ftp solitude

    Connected to fubar.net.220 fubar.net FTP server (Version wu-2.4(11) Mon Apr 18 17:26:33 MDT 1994) ready.

    Name (solitude:carlson):jeremy

    331 Password required for jeremy.

    Password:

    230 User jeremy logged in.

    ftp> cd mystuff

    250 CWD command successful.ftp> put collected-lettersftp> quit

    The ftp program sends files in ascii (text) format unless you specify binary mode:

    ftp> binary

    ftp> put foo

    ftp> ascii

    ftp> get bar

    The file foo was transferred in binary mode, the file bar was transferred in ascii mode.

    http://www.math.utah.edu/computing/unix/#ncftphttp://www.math.utah.edu/computing/unix/#ncftphttp://www.math.utah.edu/computing/unix/#ncftp
  • 8/8/2019 Useful UNIX Commands

    11/25

    grep

    Use this command to search for information in a file or files. For example, suppose that we have a file dict

    whose contents arered rojo

    green verde

    blue azulwhite blanco

    black negro

    Then we can look up items in our file like this;

    % grep red dict

    red rojo% grep blanco dict

    white blanco% grep brown dict

    %

    Notice that no output was returned by grep brown. This is because "brown" is not in our dictionary file.

    Grep can also be combined with other commands. For example, if one had a file of phone numbers named

    "ph", one entry per line, then the following command would give an alphabetical list of all persons whose

    name contains the string "Fred".

    % grep Fred ph | sort

    Alpha, Fred: 333-6565Beta, Freddie: 656-0099

    Frederickson, Molly: 444-0981

    Gamma, Fred-George: 111-7676

    Zeta, Frederick: 431-0987

    The symbol "|" is called "pipe." It pipes the output of the grep command into the input of the sort

    command.

    For more information on grep, consult

    % man grep

    head

    Use this command to look at the head of a file. For example,

    % head essay.001displays the first 10 lines of the file essay.001 To see a specific number of lines, do this:

    % head -20 essay.001

    This displays the first 20 lines of the file.

    ls

    Use ls to see what files you have. Your files are kept in something called a directory.

    % ls

    foo letter2

    foobar letter3

    letter1 maple-assignment1%

    Note that you have six files. There are some useful variants of the ls command:% ls l*

    letter1 letter2 letter3

    %

    Note what happened: all the files whose name begins with "l" are listed. The asterisk (*) is the " wildcard"

    character. It matches any string.

  • 8/8/2019 Useful UNIX Commands

    12/25

    lpr

    This is the standard Unix command for printing a file. It stands for the ancient "line printer." See

    % man lprfor information on how it works. Seeprint for information on our local intelligent print command.

    mkdir

    Use this command to create a directory.

    % mkdir essays

    To get "into" this directory, do

    % cd essaysTo see what files are in essays, do this:

    % ls

    There shouldn't be any files there yet, since you just made it. To create files, seecat oremacs.

    more

    More is a command used to read text files. For example, we could do this:

    % more poemsThe effect of this to let you read the file "poems ". It probably will not fit in one screen, so you need to

    know how to "turn pages". Here are the basic commands:

    q --- quit more

    spacebar --- read next page

    return key --- read next line

    b --- go back one page

    For still more information, use the command man more.

    mv

    Use this command to change the name of file and directories.

    % mv foo foobar

    The file that was named foo is now named foobar

    ncftp

    Use ncftp for anonymous ftp --- that means you don't have to have a password.

    % ncftp ftp.fubar.net

    Connected to ftp.fubar.net

    > get jokes.txtThe file jokes.txt is downloaded from the machine ftp.fubar.net.

    print

    This is a moderately intelligent print command.

    % print foo

    % print notes.ps

    % print manuscript.dviIn each case print does the right thing, regardless of whether the file is a text file (like foo ), a postcript file

    (like notes.ps, or a dvi file (like manuscript.dvi. In these examples the file is printed on the default printer.

    To see what this is, do

    http://www.math.utah.edu/computing/unix/#printhttp://www.math.utah.edu/computing/unix/#printhttp://www.math.utah.edu/computing/unix/#cathttp://www.math.utah.edu/computing/unix/#cathttp://www.math.utah.edu/computing/unix/emacs.htmlhttp://www.math.utah.edu/computing/unix/emacs.htmlhttp://www.math.utah.edu/computing/unix/#printhttp://www.math.utah.edu/computing/unix/#cathttp://www.math.utah.edu/computing/unix/emacs.html
  • 8/8/2019 Useful UNIX Commands

    13/25

    % print

    and read the message displayed. To print on a specific printer, do this:

    % print foo jwb321

    % print notes.ps jwb321

    % print manuscript.dvi jwb321To change the default printer, do this:

    % setenv PRINTER jwb321

    pwd

    Use this command to find out what directory you are working in.

    % pwd

    /u/ma/jeremy% cd homework

    % pwd

    /u/ma/jeremy/homework

    % ls

    assign-1 assign-2 assign-3

    % cd

    % pwd/u/ma/jeremy

    %

    Jeremy began by working in his "home" directory. Then hecd 'd into his homework subdirectory. Cd

    means " change directory". He used pwd to check to make sure he was in the right place, then used ls to see

    if all his homework files were there. (They were). Then he cd'd back to his home directory.

    rm

    Use rm to remove files from your directory.% rm foo

    remove foo? y

    % rm letter*

    remove letter1? yremove letter2? y

    remove letter3? n

    %

    The first command removed a single file. The second command was intended to remove all files beginningwith the string "letter." However, our user (Jeremy?) decided not to remove letter3.

    rmdir

    Use this command to remove a directory. For example, to remove a directory called "essays", do this:

    % rmdir essays

    A directory must be empty before it can be removed. To empty a directory, use rm.

    rsh

    Use this command if you want to work on a computer different from the one you are currently working on.

    One reason to do this is that the remote machine might be faster. For example, the command

    % rsh solitude

    connects you to the machine solitude. This is one of our public workstations and is fairly fast.

    See also:telnet

    http://www.math.utah.edu/computing/unix/#cdhttp://www.math.utah.edu/computing/unix/#cdhttp://www.math.utah.edu/computing/unix/#rmhttp://www.math.utah.edu/computing/unix/#telnethttp://www.math.utah.edu/computing/unix/#telnethttp://www.math.utah.edu/computing/unix/#cdhttp://www.math.utah.edu/computing/unix/#rmhttp://www.math.utah.edu/computing/unix/#telnet
  • 8/8/2019 Useful UNIX Commands

    14/25

    setenv

    % echo $PRINTER

    labprinter% setenv PRINTER myprinter

    % echo $PRINTER

    myprinter

    sort

    Use this commmand to sort a file. For example, suppose we have a file dict with contents

    red rojogreen verde

    blue azul

    white blanco

    black negro

    Then we can do this:

    % sort dict

    black negro

    blue azulgreen verde

    red rojo

    white blanco

    Here the output of sort went to the screen. To store the output in file we do this:

    % sort dict >dict.sorted

    You can check the contents of the file dict.sorted usingcat ,more , oremacs .

    tail

    Use this command to look at the tail of a file. For example,

    % head essay.001

    displays the last 10 lines of the file essay.001 To see a specific number of lines, do this:

    % head -20 essay.001This displays the last 20 lines of the file.

    tar

    Use create compressed archives of directories and files, and also to extract directories and files from an

    archive. Example:

    % tar -tvzf foo.tar.gz

    displays the file names in the compressed archive foo.tar.gz while

    % tar -xvzf foo.tar.gz

    extracts the files.

    telnet

    Use this command to log in to another machine from the machine you are currently working on. For

    example, to log in to the machine "solitude", do this:

    % telnet solitude

    See also:rsh.

    wc

    http://www.math.utah.edu/computing/unix/#cathttp://www.math.utah.edu/computing/unix/#cathttp://www.math.utah.edu/computing/unix/#cathttp://www.math.utah.edu/computing/unix/#morehttp://www.math.utah.edu/computing/unix/#morehttp://www.math.utah.edu/computing/unix/emacs.htmlhttp://www.math.utah.edu/computing/unix/emacs.htmlhttp://www.math.utah.edu/computing/unix/#rshhttp://www.math.utah.edu/computing/unix/#rshhttp://www.math.utah.edu/computing/unix/#cathttp://www.math.utah.edu/computing/unix/#morehttp://www.math.utah.edu/computing/unix/emacs.htmlhttp://www.math.utah.edu/computing/unix/#rsh
  • 8/8/2019 Useful UNIX Commands

    15/25

    Use this command to count the number of characters, words, and lines in a file. Suppose, for example, that

    we have a file dict with contents

    red rojo

    green verde

    blue azulwhite blanco

    black negroThen we can do this

    % wc dict

    5 10 56 tmp

    This shows that dict has 5 lines, 10 words, and 56 characters.

    The word count command has several options, as illustrated below:

    % wc -l dict5 tmp

    % wc -w dict

    10 tmp

    % wc -c dict

    56 tmp

    In this Document . . .

    Command words and arguments in bold typeface are shown exactly as you type them. Note thatmost are in lowercase. They must be typed that way: UNIX treats uppercase letters as different

    from their lowercase counterparts. For items shown in italics, substitute an appropriate value.

    Type the punctuation shown, such as a hyphen or vertical bar.

    Control characters, typed by holding down the CTRL key while typing the character, are shown by

    the notation ^x, where x is the character.

    You must finish all UNIX commands by pressing the RETURN key, which is not shown here.

    Connecting and Logging In

    Connecting from Another Computer

    If you are using another computer on the campus network (UTnet) or on the Internet, and if that computer

    has a telnet command, you can use it to connect to a UNIX host. If the other computer is also running

    UNIX, you can connect using rlogin. If your computer offers ssh, the Secure SHell, you can also connectusing ssh orslogin.

    Connecting through Telesys

    You must have a modem and a computer, and your user number must be validated to use the Telesys dial-

    up system.

    If you use SLIP or PPP software provided in the UT Connect package, it will make the Telesys connection,

    and you can use telnet to connect to a UNIX host.

    Logging InFor your first login, your login name is the user number issued to you by ACITS, in lowercase. When the

    UNIX system prompts you for a password, give the password originally issued for your user number, also

    in lowercase.For your first login, a special program will prompt you for a new UNIX password, possibly for a new

    UNIX login name, and for other initialization information. Then it will log you out. The login name you

    choose must be unique: it cannot be used by anyone else on the system. It will also be part of your e-mail

    address, so you should choose something appropriate.

  • 8/8/2019 Useful UNIX Commands

    16/25

    Make up a password that is six or more characters long, mixing uppercase, lowercase, and numbers to

    make it difficult for others to guess. This password is the only thing that keeps someone else from using

    your account and having full access to your work.

    The program may ask you to choose a login shell, which is a UNIX command interpreter. The C shell

    (/bin/csh) is recommended. For this document, the C shell is assumed to be the command interpreter-unlessotherwise stated. The program will also prompt you for optional data to put into a database that other users

    on the Internet can view. This includes such items as your name, office address, and phone number. PressRETURN to leave any item blank.

    To add or change data in a later session, use the command:

    chfn

    Exceptions: For the UTS system, you must run chfn on the machine named curly.cc.utexas.edu. For theADS and CCWF systems, send your request to

    http://www.utexas.edu/cc/help/remark/

    The Shell's Prompt for Commands

    After you log in, you will see a prompt from the shell. The C shell's prompt usually includes the hostmachine's name. When you see the shell prompt, such as ccwf.cc.utexas.edu%, you can issue UNIX

    commands.

    Logging Out

    IMPORTANT: Don't just turn off the terminal or workstation or disconnect the phone, and do not abandon

    a terminal or workstation that seems "locked up". When you are through with your UNIX session, log out

    by typing:

    logout or^d

    If you see a new UNIX login prompt, press ^d again. If you see a new Telesys> prompt, type:

    exit

    If you can't get a response at all and are unable to log out, see "Killing a Detached or Runaway Job" in this

    document.

    Changing Your Password

    To change your password, type the command:

    passwd

    You will be prompted for your old password, then for your new one (twice for confirmation). If the two

    new passwords match, the change will take effect in about one hour. If they do not match or are otherwise

    unacceptable, you will be prompted to try again. Neither the old nor new password will display on the

    screen. Changing your password on UTS, which must be done on the machine named curly.cc.utexas.edu,

    does not affect your password for Telesys, CCWF, ADS, UMBS, or any other system.

    Correcting Typing Errors

    http://www.utexas.edu/cc/help/remark/http://www.utexas.edu/cc/docs/#killjobhttp://www.utexas.edu/cc/help/remark/http://www.utexas.edu/cc/docs/#killjob
  • 8/8/2019 Useful UNIX Commands

    17/25

    To correct an error before you press the RETURN key:

    Press either the DELETE or BACKSPACE key to back up over a character, depending on the

    system.

    Press ^w to back up over a word.

    Type ^u to erase the entire line.

    Special Characters

    ^c

    Interrupts and aborts execution of the current process, which cannot be restarted.^z

    Suspends a process (temporarily stops it by putting it in the "background") so that you can give other UNIXcommands. To resume the process, use fg (foreground) or%n, where n is the background job number. To

    disable ^z (make it undefined), give the command:

    stty susp u

    Writes to the file named to the right of this symbol instead of to standard output. Thus:

    cat myfile

    displays contents of "myfile" at your terminal (standard output), but:

    cat myfile > listout

    copies it to file "listout" instead, overwriting and destroying any previous contents of the file "listout". (Inthe C shell, a priorset noclobber command prevents such destruction.)

    >>

    Appends output to the file named to the right of this symbol. Thus:

    cat nextfile >> listout

    appends a copy of "nextfile" to file "listout" instead of overwriting what is already in "listout".

    |

    Creates a "pipe" so that output from one program (on left) becomes input to the next one (on right). Thus:

    ls | lpr -Pcom_lw

    sends output from the ls (listing) program to the lpr (printing) program.

    *

    Matches zero or more characters in a filename. For example, A* matches A, AbC, ARGUE, African, etc.

    ?

    Matches any single character in a filename. For example, A?C matches AAC, ABC, ACC, etc.

  • 8/8/2019 Useful UNIX Commands

    18/25

    \

    Prevents the following character from being interpreted as special. For example, \* makes * an ordinary

    character.

    The shell performs filename matching and input/output redirection before calling any program that uses the

    files.

    Setting Your Terminal Type

    Some programs must know what type of terminal you are using in order to process control characters

    correctly. To identify your terminal to the C shell, give the command:

    setenv TERM type

    where type is the terminal type, such as vt100. Your terminal type should already be defined by

    initialization files set up for you when you first used a particular ACITS UNIX system.

    Getting Online Help

    Online UNIX documentation consists of "man" (manual), pages that you can display or print by using theman program. For example, to display the man page for the rm (remove) program, type:

    man rm

    For information on the man program itself, type:

    man man

    The program pauses after displaying each screenful of text. Press the space bar to continue, or press q to

    quit.

    To print a man page, "pipe" the output of the man program to the ul program (for underline and boldface

    removal, which some printers can't do) then pipe that output to the lpr program--like this:

    man rm | ul-Tdumb | lpr -Pacwl_lw

    This prints the rm man page on the laser printer at the Student Microcomputer Facility. If you don't know

    which man page you need, type:

    aproposkeyword

    to get a list of man pages that contain keywordin their title lines.

    On the ADS system, get additional online help by using the InfoExplorer program. Type info -h to getstarted.

    Longer documents and frequently asked questions can be searched and displayed by using your Web

    browser to connect to:

    http://www.utexas.edu/cc/unix/

    Files and Directories

    A UNIX filename or directory name can contain up to 255 letters, digits, and punctuation characters (best

    limited to period and underscore). To list names of files in your own directory, type:

    http://www.utexas.edu/cc/unix/http://www.utexas.edu/cc/unix/
  • 8/8/2019 Useful UNIX Commands

    19/25

    ls

    This will not list filenames that begin with a period, unless you include the -a (all) option, like this:

    ls -a

    Names of initialization files typically begin with a period. For example, the C shell executes commands in.login each time you log in, and those in .cshrc each time you start up the C shell. The initialization file for

    the Bourne shell or the Korn shell is .profile.

    Otherls options include:

    -l

    long form, gives file protections, size in bytes.-F

    marks directory names with a slash, executable files with an asterisk.

    To list a subset of your files, use special characters. For example, to list all filenames beginning with A,

    use:

    ls A*

    For complete information about the ls command, see:man ls

    Creating and Editing Files

    To create and alter files on a UNIX system, use a text editor. The most common one is the vi editor. Its use

    is described in Introduction to UNIX, CCUG-1. The pico editor is very easy to use, with an on-screen menu

    of commands and built-in help.

    Emacs is another popular editor. A summary of Emacs commands is in GNU Emacs Pocket Reference

    List, CCRL-34, available free at the Help Desk.

    NOTE: To use most editors, your terminal type will need to be defined. A definition of vt100 works in

    most cases.

    Displaying a File at Your Terminal

    Use the cat (catenate) or more command to display files at your terminal. For example:

    cat source1 source2

    displays "source1" and "source2" in that order.

    more testfile

    displays "testfile", pausing after each screenful. Press the space bar to see each new screen.

    Printing a File

    To send files to a printer, use lpr. For example:

    lpr -Pfacsmf_lw source1 source2

    prints files "source1" and "source2" on a laser printer at the Student Microcomputer Facility (SMF) in the

    Flawn Academic Center (FAC). For information about options, output devices, and locations, see:

    http://www.utexas.edu/cc/docs/ccrl34.htmlhttp://www.utexas.edu/cc/docs/ccrl34.htmlhttp://www.utexas.edu/cc/docs/ccrl34.htmlhttp://www.utexas.edu/cc/docs/ccrl34.htmlhttp://www.utexas.edu/cc/docs/ccrl34.html
  • 8/8/2019 Useful UNIX Commands

    20/25

    man lpr andhttp://www.utexas.edu/cc/unix/print-service/

    On ADS, use InfoExplorer. To learn how, type

    info -h

    Deleting a File

    Use rm (remove) to delete files from your directory. For example:

    rm trashfile

    The -i (interactive) option to rm causes the system to request confirmation of each file deletion. This option

    may prevent accidental deletions and is useful if you are removing several files, as in:

    rm -i *file

    To delete a file that starts with a hyphen, use

    rm - file

    Setting a Search Path

    Your command search path is the sequence of directories the shell searches to find commands you issue.

    For the C shell, to add a directory to the search path, use set path. For example:

    set path=($path /usr/lang) ; rehash

    adds /usr/lang to your current search path, $path. But this works only for the current login session. If you

    want your path set as above for EVERY login session, put the set path command in your.login file.

    Killing a Detached or Runaway Job

    If your terminal gets disconnected from your job or if it "locks up", you can kill the detached processes this

    way:

    1. Log in again to the same machine (if need be, from another terminal) and type: tty (tells which

    terminal line you are now using) ps -u username(username is your own username. This lists all

    your running processes)

    2. For lines that have "csh" in the COMMAND column and that have a terminal line in the TT

    column different from your current terminal, look in the PID column for the process id number of

    that C shell.

    3. Send that C shell's process id (pid) a hangup signal:

    kill -HUP pid

    4. Repeat the ps -uusername command to make sure all unwanted processes are gone. If not, reissuethe kill command like this:

    kill -9 pid

    Running Programs

    To compile a Fortran program using the UNIX FORTRAN-77 compiler, f77, type:

    http://www.utexas.edu/cc/unix/print-service/http://www.utexas.edu/cc/unix/print-service/http://www.utexas.edu/cc/unix/print-service/
  • 8/8/2019 Useful UNIX Commands

    21/25

    f77file

    wherefile is the name of the source file. On ADS, you can also use xlforxlf90. If the source filename ends

    in .f it is taken to be a FORTRAN-77 program.To compile a Pascal program, type:

    pc file

    wherefile is the name of the Pascal source file, which normally has .p as its final two characters.

    Exception: on ADS systems, use

    xlpfile

    To compile a C program, type:

    ccfile

    wherefile is the name of the C source file, normally having .c as its last two characters. On ADS systems,

    you can also use xlc.To compile a C++ program with the GNU C++ compiler, type

    g++ file

    All of these compilers compile and load object code into executable files named a.out. To execute your

    program, simply type:

    a.out

    If you get the message "a.out: Command not found", check to be sure that your command search path is set

    correctly. Or you may be able to solve the problem by using the command:

    ./a.out

    to specify your current working directory. To write object code to some file other than a.out, use the -ocompiler option, like this:

    cc -o output

    where outputis the name of your executable file. To compile only, use the -c option. In this case, the

    compiled program is written to a file with the same name as the source file but with the final .f, .p, or.creplaced by .o; no loading or linking takes place.

    NOTE: Programs compiled on one machine architecture will not run on another. For example, an a.out filecompiled on the CCWF system will not execute on UTS. To debug your C, Pascal, FORTRAN, and

    assembly language programs, compile them with the -g option, then use an interactive debugging program.For information on available debugging programs, type:

    apropos debug

    For other compiler options, see the man pages forf77, PC, and cc. On UNIX systems running AIX, see the

    man pages forxlf, xlc, and xlp.

    To print a listing of your program, type:

  • 8/8/2019 Useful UNIX Commands

    22/25

    lpr -Psite -psourcefile

    To include line numbers, use:

    cat -nsourcefile | lpr -Psite -p

    Summary of Useful Commands

    The following commands are grouped alphabetically by function. Unless noted otherwise, each has a man

    page describing it in full. Commands marked "C shell only" are described in the csh man page (except on

    ADS systems, where you should use InfoExplorer for information).Access Control

    exit - terminate a shell (see "man sh" or "man csh")

    logout - sign off; end session (C shell and bash shell only; no man page)

    passwd - change login password

    rlogin - log in remotely to another UNIX system

    slogin - secure version of rlogin

    Communications

    from - list senders of mail

    Mail - send and receive mail

    mesg - permit or deny terminal messages and talk requests

    pine - send and receive mail (easiest for new users)

    talk - talk to another logged-in user (full screen)

    write - write to another logged-in user

    Programming Tools

    ar - archive and library maintainer

    as - assembler, specific to each machine architectureawk - pattern scanning and processing language

    CC - C++ compiler (cxx on UTS; xlC on ADS)

    cc - C compiler (xlc on ADS)

    crontab - maintain periodic taskscsh - C shell command interpreter

    dbx - source-level debugging program

    f77 - FORTRAN compiler (xlf on ADS)

    g++ - GNU C++ compiler

    gcc - GNU C compiler gdb - GNU Project debugger

    gprof - display profile of called routines

    kill - kill a process

    ld - the UNIX loader

    lex - generate lexical analysis programslint - check C source code

    make - manage multipart program projects

    maple - symbolic mathematics program

    nice - run a command at low priority (see "man nice" or "man csh")

    nohup - run a command immune to hangups

    PC - Pascal compiler (xlp on ADS)

    perl - Popular script interpreterprof - display profile data

    ranlib - convert archives to random libraries

  • 8/8/2019 Useful UNIX Commands

    23/25

    sh - Bourne shell command interpreter

    /bin/time - time a command

    yacc - generate input parsing programs

    Documentation

    apropos - locate commands by keyword lookup/usr/bin/X11/dxbook - start the BookReader program (UTS only)

    info - start the InfoExplorer program (ADS only)

    man - find manual information about commands

    whatis - describe what a command is

    whereis - locate source, binary, or man page for a program

    Editors

    emacs - screen-oriented text editor

    ex - line-oriented text editor

    pico - simple, screen-oriented text editor (easiest for new users)

    sed - stream-oriented text editor

    vi - full-screen text editorvim - full-screen text editor ("vi-improved")

    File and Directory Management

    cd - change working directory

    chmod - change the protection of a file or directory

    chquota - change disk quota on ACITS UNIX systemscmp - compare two files

    comm - select/reject lines common to two sorted filescompress - compress a file

    cp - copy files

    crypt - encrypt/decrypt files (not on ADS)

    diff - compare the contents of two ASCII files

    file - determine file type

    grep - search a file for a pattern

    ln - make a link to a file

    ls - list the contents of a directorymkdir - create a directory

    mv - move or rename files and directories

    pwd - show the full pathname of your working directory

    quota - display disk usage and limits

    rm - delete (remove) files

    rmdir - delete (remove) directories

    sort - sort or merge files

    tee - copy input to standard output and other files

    tr - translate charactersumask - change default file protections

    uncompress - restore compressed file

    uniq - report (or delete) repeated lines in a file

    wc - count lines, words, and characters in a file

    File Display and Printing

  • 8/8/2019 Useful UNIX Commands

    24/25

    cat - show the contents of a file; catenate files

    fold - fold long lines to fit output device head - show first few lines of a file

    lpq - examine the printer spooling queue

    lpr - print a file

    lprm - remove jobs from the printer spooling queuemore - display a file, one screen at a time

    page - like "more", but prints screens top to bottompr - paginate a file for printing

    tail - show the last part of a file

    zcat - display a compressed file

    File Transfer

    ftp - transfer files between network hosts

    rcp - transfer files between networked UNIX hosts

    scp - secure version of rcp

    rz - receive files using ZMODEM protocol

    sz - send files using ZMODEM protocol

    Miscellaneous

    alias - define synonym commands

    chsh - change default login shell

    clear - clear terminal screen

    echo - echo arguments

    learn - request computer-aided instruction (not on CCWF)

    pbm - portable bitmap manipulation programs

    popd - pop the directory stack (C shell only)

    pushd - push directory on stack (C shell only)script - make typescript of terminal session

    setenv - set an environment variable (C shell only)

    stty - set terminal options

    News/Networks

    lynx - text-only Web browser for display terminals

    netscape - Web browsernetstat - show network status (on UTS, /usr/sbin/netstat)

    Pnews - submit USENET news articles

    rlogin - login remotely on another UNIX system

    slogin - secure version of rlogin

    tin - read/post USENET news articles

    trn - read/post USENET news articles

    rsh - run shell or command on another UNIX system

    ssh - secure-shell version of rsh

    telnet - run Telnet to log in to remote host

    Process Control

    (The following commands function under the C shell, bash, and ksh. They do not have separate man

    pages.)

    bg - put suspended process into background

    fg - bring process into foregroundjobs - list processes

  • 8/8/2019 Useful UNIX Commands

    25/25

    ^y - suspend process at next input request

    ^z - suspend current process

    Status Information

    spend - lists year-to-date ACITS UNIX charges

    date - show date and timedf - summarize free disk space

    du - summarize disk space used

    env - display current environment or run programs under modified environment

    finger - look up user information

    history - list previously issued commands (C shell, bash, and ksh only)

    last - indicate last login of userslpq - examine spool queue

    manpath - show search path for man pages

    printenv - display environment

    Ps - show process status

    pwd - display full pathname of working directory

    set - set shell variables (C shell, bash, and ksh only)

    stty - set terminal optionsuptime - show system load, how long system has been upw - show who is on system, what command each job is executing

    who - show who is logged onto the system

    whois - Internet user name directory service

    Text Processing

    checknr - check nroff/troff files

    col - filter reverse line feedsdvips - convert TeX DVI files into PostScript

    eqn - typeset mathematics with troff

    ispell - check spelling interactively

    macref - make cross-reference listing of nroff/troff macro filesneqn - format mathematics with nroff

    nroff - format text for simple display

    pic - make simple pictures for troff input

    psdit - filter troff output for Postscript printerspell - find spelling errors

    tbl - format tables for nroff/troff

    troff - format