Skip Navigation
 Search | Directories | Reference Tools
UW Home > Discover UW > IT Connect 

Unix Commands

This document provides examples of the use of many of the most common Unix commands. The first thing to remember about Unix commands is that are case sensitive.

For more details on a command see the man page for the command. For example, to see more information about the command rm, enter the command

man rm

To display a list of commands related to a topic enter

man -k topic

You should also understand that some commands you may be looking for are not part of the basic Unix operating system but, instead, belong to the shell that interprets your commands. The most commonly used shell is the C-shell, which is described in the man csh page. For example, the following commands are described in the man csh page and do not have separate man pages of their own:

      < << >> > | (I/O redirection and piping)

... and many others.


Your Account

      passwd            ... set a new password for your account


        DO:                        TO:
      ---------------   ---------------------------------------------
      pwd               ... find out what your current working
                        directory is
      mkdir playdir     ... create a new subdirectory called
      rmdir junkdir     ... remove subdirectory 'junkdir' (must be
                        empty of files and subdirectories)
      cd /usr/bin       ... change to '/usr/bin' directory
                        (directory specification is relative to
                        the root directory)
      cd class/cs108    ... change to a subdirectory named
                        'class/cs108' (directory specification is
                        relative to current working directory)
      cd ..             ... change to directory one level above
                        current working directory
      cd                ... change to home directory for the account
                        you are using
      du                ... display the number of disk blocks in use
                        (the total combined size of all files)
                        in each directory and subdirectory.


        DO:                        TO:
      ---------------   ---------------------------------------------
      ls                ... list files in the current working
      ls notes          ... list file in the subdirectory
                        named 'notes'
      ls -l             ... list all files in the current working
                        directory, along with each file's
                        permission, owner, size in bytes and date
                        of last modification.
      ls -a             ... list files in the current working
                        directory, including dot files (those
                        files with names beginning with a period)
      ls -F             ... list files in the current working
                        directory, indicating executable files
                        with an asterisk (*) and subdirectories
                        with a /
      find docs -name \\*\.memo -print
                        ... list all files in the directory
                        'docs' and any subdirectories of 'docs'
                        with filenames ending in '.memo'. The
                        \ is necessary before the * to insure
                        that is is interpreted as a wild character.
      cp file1 file2    ... copy the file 'file1' to a file named
                        'file2' (original file remains intact with the
                        same name)
      mv oldf newf      ... move the file 'oldfile' to a file named
                        'newfile' (equivalent to renaming a file)
      rm badfile        ... remove the file 'badfile' (the file is
                        permanently removed and cannot be recovered)
      rm -i *.c         ... remove all files in the current directory
                        with the suffix '.c' and be asked for
                        confirmation on each file
      chmod a+r resul   ... grant read access of the file 'resul'
                        to all users
      cat shortfile     ... display the file 'shortfile'
      more longfile     ... display the file 'longfile', a
                        screenful at a time
      head big          ... display the first ten lines of
                        file 'big'
      head -25 big      ... display the first 25 lines of file 'big'
      tail big          ... display the last ten lines of file 'big'
      tail -25 big      ... display the last 25 lines of file 'big'
      grep done tasks   ... display all lines within file 'tasks'
                        containing the string 'done'


        DO:                        TO:
      ---------------   ---------------------------------------------
      ps                ... list the status of your jobs by
                        process identifier (PID)
      ps aux           ... list the status of all jobs by process
                        identifier (PID)
      jobs              ... list the status of all jobs by job
      <CTRL>z           ... suspend the job currently running in
                        the foreground
      bg                ... resume the most recently suspended job
                        into the background
      bg %2             ... resume job number 2 in the background
      fg %2             ... resume job number 2 in the foreground
      fg %3             ... bring job number 3, which is running
                        in the background, into the foreground
      kill %2           ... kill job number 2
      kill 1234         ... kill job with PID 1234


        DO:                        TO:
      ---------------   ---------------------------------------------
      ssh homer.u      ... establish an interactive session on
                        computer 'homer'
                        ... transfer a file to or from computer

Communicating With Others

        DO:                        TO:
      ---------------   ---------------------------------------------
      who               ... find out who is logged on to the
      w                 ... find out who is logged on to the
                        computer and what they are doing
      finger suzz       ... display information about user 'suzz'
      biff y            ... be notified if mail arrives. To turn
                        off notification, enter the command 'biff n'
      pine     ... start pine mailer.  Pine is an alternative
                 to 'mail' that many people find easier to use
                 than 'mail'


        DO:                        TO:
      ---------------   ---------------------------------------------
      cal 6 1990        ... display a calendar of June, 1990.
      date              ... display current date and time
      script            ... start recording of all screen
      exit              ... stop script recording (text from
                        recorded session will be in a file named
                        typescript )
      alias dir ls -Fal ... alias 'dir' to represent the command
                        'ls -Fal'
      unalias dir       ... remove the alias for 'dir'
      alias             ... show all current aliases

Control Codes (Used When at Unix Command Line)

        DO:                        TO:
      ---------------   ---------------------------------------------
      <CTRL>u           Delete entire line
      <CTRL>w           Delete the preceding word
      <CTRL>h           Delete the preceding character
      <CTRL>c           Abort the program currently running
      <CTRL>z           Suspend the program currently running (use
                        fg or bg to resume the program in the
                        foreground or background, respectively)

Redirecting and Piping

      cc myprog.c > listing
                       ... run C compiler on 'myprog.c' source file,
                       redirecting compilation messages to a file
                       named 'listing'. The resulting file would NOT
                       include any diagnostic messages.
      cc myprog.c >& listing
                       ... run C compiler on 'myprog.c' source file,
                       redirect compilation messages, including
                       diagnostic messages, into a file named 'listing'.
      ps aux | more   ... list all current jobs on the system,
                       piping the result to more for viewing one
                       screen at a time
      cat frog >> rat
                       ... concatenate the contents of file 'frog'
                       onto the end of file 'rat'