Computing Services

Classroom Services & Room Scheduling Unit

Web Services

E-Learning & Instructional Technology

Distance Education

Related Sites

Accessibility Statement. Privacy Statement.

symbol for authentication required denotes that authentication is required.

Frequently Used 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 UNIX manual pages (available on any UNIX machine using the man command. The commands shown here are of the Solaris 2 or GNU varieties. Some of these commands such as scripts that we have written in-house are specific to the SPH environment and will not work on non-SPH UNIX machines.

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 some file is an argument to the cat command rather than the word, file).

alias alias-term command-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 equal to command-string. If command-string has 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.
cat file
The cat command displays the contents of the file named by file. 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 the more command.
chdir directory
cd directory
The chdir command moves you (changes your current working directory) to directory. Entering cd without the directory argument will move you to your home directory.
Examples:
cd /usr/sph
moves you to the sph directory inside of the usr directory.
cd ..
moves you to the parent directory of your current directory.
chmod permissions path
The chmod command changes the access permission associated with a non-AFS file or directory ("file" will be used here to refer to either a file or a directory). In most cases, the only non-AFS directory (i.e. directory that is not on the file servers) where SPH users have the ability the change file permissions is /tmp. For a discussion of access control on AFS directories, see the fs command.

Each file has three types of access: read (r), write (w) and execute (x). In a ls -al file listing, the abbreviations 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 (w) 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 three columns (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 for everyone 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 new permissions.

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.

The permissions can also be specified using abbreviations rather than numbers. Using this method, some of the permissions can be changed without affecting others. The permissions format is <u, g or o> <+ or -> <r, w or x>. 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's access unchanged.
cp file1 file2
The cp command creates an identical copy of the file, file1, and names the copy, file2. Note that the ownership of file2 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 Greenwich Mean Time (GMT), universal time.
diff file1 file2
The diff command compares the contents of two text files and displays the differences. The lines preceded with < are from file1. The lines preceded by > are from file2. Each section of differences is separated by ---.
du
The du (disk usage) command displays the amount of space occupied by files in the directories of the UNIX filesystem. The command will display subtotals (usually in kilobytes) for all subdirectories and a grand total for the current working directory if entered without any command line arguments.
enscript textfile
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 pages reduced 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 UNIX shell. Exactly what happens when you type exit depends on how you started the current shell. For example, it you started this UNIX session (shell) with the telnet command from another machine, exit returns you to the command prompt (shell) of the machine that you telnetted from. Often, exit just closes your window (either an xterm window or terminal program window) or returns you to a login: prompt. In this case, exit is effectivly the same as using the logout command.
finger name@address
The finger command displays information about user accounts with names (usernames or proper names) 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 (this varies from machine to machine). When fingering @umich.edu, first and last name separated by a period may be used, e.g. finger cranklin.gabrothnik@umich.edu.

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 the who command).

An electronic mail address can often be verified or determined using the finger command. For example, finger sadie@somehost.somewhere returns a list of all users with sadie in their name on the machine somehost.somewhere

fs subcommand arguments ...
The fs command is specific to those UNIX sites, such as SPH, that are using the AFS file system for their networked file service. See the AFS section of our Online Documentation page for detailed information about using AFS.

The fs command is actually several commands rolled into one. Many of these commands replace the functionality of traditional UNIX commands such as chmod (which does not behave as expected in AFS file space). For information on all the subcommands of fs, request help by entering the command, fs -help. A few of the most common fs uses are detailed below.

fs listacl directory
Lists the access control list (a list of users and groups who have various levels of access) for the specified directory.

fs setacl directory user_or_group access_list
Using this command, you can add, delete or change the level of access for any user or group for the specified directory. See the CAEN document, "Setting AFS File Permissions", for a thorough discussion of access control lists and the related fs commands. Some example uses of the fs setacl command are shown below:

    fs setacl . system:anyuser none    Deny access to the world for the
                                       current directory.

    fs setacl . alfredo all            Give full access to the user,
                                       alfredo, for the current
                                       directory.

    fs setacl . wwwsrvr rliw           Give only read, lookup, insert
                                       and write access to the user,
                                       wwwsrvr, for this directory.
    

Things to keep in mind when changing access control lists:

  • If you grant access to a user for a given AFS directory, at least lookup (l) access must be granted to some identity which this user matches (e.g. their own name, some group name or system:anyuser) all the way up to the top AFS directory, /afs/sph.umich.edu. The anonymous user, system:anyuser, always has lookup access down to the level where the average user has the power to change access (e.g a user's home or group directory). Beyond this level, the user must set the appropriate permissions.
  • Changing access for a given directory only affects that directory. If the directory already contains subdirectories, you may also need to adjust the permissions on these. Any new directores created after the change, however, will inherit the access control list of their parent directory.

fs listquota
Displays the current limit and usage for the volume on which your current directory resides. If you ever get "device full" or other messages that indicate that you are out of file space in your home or group directories (AFS), use this command to determine if indeed you have exceeded your allocation.

grep pattern file
The grep command searches one or more files, specified by file, for the text string specified by pattern. For example, grep 'dna' seqfile1 will list all lines found in the file, seqfile1, which contain 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 your current directory (see wildcard characters for an explanation of *).
gzip file
gunzip file.gz
The gzip command will safely compress a file so that it occupies less disk space. The compressed file will be renamed to include a suffix of .gz. For many text files, the compressed file will be substantially smaller than the original file. Once compressed, the file cannot be used again without first uncompressing it. The gunzip or gzip -d commands do the opposite of gzip; they uncompress a file and rename it by removing the .gz suffix.

The gunzip -c somefile.gz command is useful to uncompress a file temporarily to the screen without removing the original compressed file. For large text files, gunzip -c somefile.gz | less is an easy way move back and forth through the file on the screen using the less command while leaving the compressed file intact on the disk.

head file
tail file
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.
kill id-number
The kill command terminates the process with the id, id-number. The process id can be determined with the ps 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 a zombie 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.
less textfile
The less command will display a file much in the style of the more command but has the added functionality of allowing navigation through the file using vi-like key commands.
lpr textfile
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 -Plab2 sequence sends the file, sequence, to the printer named "lab2".
lpq
The lpq command displays the status of jobs (documents) in the print queue (waiting to print). The -Pprinter option specifies which printer queue to check. For example, lpq -Plab2 checks the status of documents waiting to print on the printer named "lab2".
lprm job-number
The lprm command removes the waiting document, job-number, from the print queue. The value for job-number can be obtained from the lpq command. If the job is to be removed from a print queue other than the default, the -Pprinter parameter is used to specify the print queue (just as with lpr and lpq). Note that each user may only remove print jobs that their own print jobs.
ls pattern
The ls command lists the files and directories in a directory. If pattern is the name of a file, only that file (or files if wildcards are used) is listed. If pattern is a directory name, the contents of that directory are listed. If pattern is omitted, all the files and directories in your current directory are listed. The output of the ls command may be piped into the more command to pause the listing after each screenful of text (e.g. ls -al | more).
Here are a few of the options for the ls command:
-a
lists all files 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 long format. This format includes the protections (changable with chmod) on each file and the owner of the file.
-F
highlights directories with a trailing /, executable files with a trailing * and symbolic links with a trailing @ in a listing.
Examples:
ls
lists every file (except those filenames that begin with a period) in in the current directory.
ls -al /bin
lists 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.
man command
The man command displays the standard UNIX manual page for the command you specify. These pages may be somewhat cryptic for some users but generally tell you all you would ever want to know about the command.

Under Solaris 2, the man pages are indexed in a file that doesn't get built as well as we'd like. Using man -F command will force man to look through all the manual directories for the desired help instead of simply relying on the index file.

md dir1
mkdir dir1
The mkdir command creates the directory, dir1, within your current directory (unless the specification of dir1 begins with a /).
more file1
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:
  • <SPACE> to display to the next page of text,
  • <ENTER> to display only one more line of text,
  • / followed by a word and the <ENTER> to search for that word in the remaining text of the file,
  • ? to see all the operations available in more,
  • q or CONTROL-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, the ls -al command often produces long directory listings which are better viewed a screen at a time by entering ls -al | more.

See also the less command.

mv name1 name2
The mv command moves and/or renames the file or directory, name1. If name2 is an existing directory, name1 will be moved (not copied) into the directory, name2. If name2 is not an existing directory, name1 (whether it be a file or directory) will simply be renamed into name2. It is possible to move and rename name1 at the same time if name2 is a new name withing an existing directory. Any file file already existing with name2 will be overwritten by the renaming or moving of name1 unless mv -i is used, which asks the user for confirmation of destruction of existing files.
ps
The ps command displays a list of the processes currently running on the machine that you are logged into. If no arguments are entered with the ps command, only the processes that you own (i.e. that you are running) under the controlling terminal are shown (which is usually just everything you have started under the current shell). The -e or -A options will list all processes on that machine, including those processes being run by other users. The -u username lists all processes owned by the user, username. The -f option lists more information per line of output for each process shown.
Examples:
ps -u username
List all the processes running for user, username. This is useful to see processes that you may have running in the background from previous sessions.
ps -ef
List 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 full path of your current working directory. In other words, it tells you what directory you are in.
rm yourfile
The 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 -r somedir will remove the subdirectory somedir as well as all the subdirectories and files within that subdirectory as long as all directories are empty. rm -Rf somedir will remove somedir and all its subdirectories even if they are not empty (be careful with that one!).
rmdir dir1
The rmdir command deletes the empty subdirectory, dir1. To delete non-empty subdirectories, see rm -r.
rup
Displays the load of a remote machine. See uptime.
tail file
Lists the last few lines of a file. See head.
telnet address
One way of connecting to another machine (usually a UNIX -based machine) over a network using a text-only (no graphics) interface.

From a ethernet-networked Macintosh, telnet can be accomplished using NCSA Telnet.

From a ethernet-networked machine running Microsoft Windows, telnet can be achieved using one the LAN Workplace programs (Telnet Presenter or tnvt220) or Windows 95/NT telnet.exe.

From a UNIX machine, the telnet command can be used.

From a non-networked computer, one must dial into a PPP server (or other internet-modem connection) before telnet can be used.

uptime
rup remote_hostname
These commands display the current load of the machine. The load gives an idea of how busy the machine. An idle machine may have a load of less than 0.10. A machine may begin to appear sluggish for users logged in at the workstation when the load creeps over 1.0. The uptime command displays the load for the machine that the user is currently logged into. The rup hostname command displays the load for some remote machine named hostname. The rup command can be used to query a number of machines to determine which is the least busy.
wc yourfile
The 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.