UNIX Commands: Quick Reference

This is a guide to some of the most commonly used commands in UNIX terminal mode. Most of the commands will work the same way in *NIX variants such as Linux and Mac OS X's terminal.

Examining Files

cat display file
cat file.. display contents of file
more display file by screenful (BSD)
more file.. display one screenful at time. Use SPACE BAR to
display next screenful. Use RETURN to display next line.
tail display last part of file
tail[+/-n] [file].. by default, displays text from tenth line from end of text

Managing Files

cp copy file
cp file.1 file.2 make copy of "file.1" called "file.2"
ls list contents of directory
ls[-ltdru] file.. list contents of directory options:
-l long format
-t by time of modification
-d directory status
-r list in reverse order
-u by time of last access
mv move or rename files and directories
mv file.1 file.2 change name of "file.1" to "file.2"
mv file...directory move one or more files to specified directory
mv directory.1 directory.2 change name of "directory.1" to "directory.2"
rm remove files or directories
rm [-ir] file... remove one or more files or directories options:
-i interrogative
-r remove specified directories and their contents

Text Editing

vi invoke visual editor  
vi file... invokes vi text editor to edit specified file(s) option:
-r recover lost file

Formatting Files

pr prepare file for printing
pr [option] file paginate file for printing options: -h change header -t suppress header
nroff format text
nroff [-mm,-ms] file.. format text according to commands and defaults options:
-mm specifies use of mm macros package
-ms specifies use of ms macros package
checkmm check mm macro input
checkmm file.. check input files for formatting errors
checknr check ms macro input (BSD)
checknr file.. check input files for formatting errors

Printing Files

lp print file on line printer
lp [options] file.. puts specified file(s) in line printer queue options:
-c send copy of file for printing
-m send mail when file printed
-n# make #- number of copies of printout
-d destination printer
lpstat display information about the status of the LP print
cancel cancel lp command


mail send or receive mail among users
mail username sends electronic mail to specified users
who lists users currently on-line
who [am i] [am I displays login name, tty number, and login time for users currently logged in.
write write to another user
write username[tty.no] send lines from your terminal to another. to end message, type ^D.
mesg permit or deny write messages
mesg [n] [y] with n argument, prohibit messages sent to you via write
with y argument, permission to write to you is restored

Working With Directories

cd change directory
cd dir.name establish specified directory as working directory
cd .. establish parent of working directory as working directory
mkdir create directory
mkdir dir.name.. make one or more directories
pwd print working directory
pwd display absolute pathname of working directory
rmdir remove directory
rmdir dir.name.. remove specified directories only if empty.
Also see rm -r.

Managing Background Processes

& detach commands. At end of command line, causes shell to execute command in background, e.g., spell file &.
ps process status; displays information about each currently active process
kill -9 terminate process
kill -9 process.id.. terminates one or more processes specified by process ID

Account Management

passwd   change your password

On-Line Documentation

help provides help
help [args] explains use of command or meaning of diagnostic
man display on-line UNIX manual
man [option][chapter]
prints section for any specified UNIX command

Other Utilities

cal [month] year
display calendar
displays calendar for any year or month between 1 and 9999 A.D.
cmp compare two files
cmp file.1 file.2 compares two files: if different, displays line and character number where first difference appears, then stops
chmod[who] operator permission file...
change mode
changes read, write, and execute privileges for file for owner, group, others, or all


Who: u user (owner)
g group
o others
a all of above
Operator: + add permission
- remove permission
Permissions: r read
w write
x execute


display date and time
diff[-bh] file.1 file.2
display differences between files
Compares two files and indicates what lines must be changed to make first file identical to second:
Options: -b ignore trailing blanks
-h half-hearted option; incapable of handling complex changes
echo argument
repeat command line arguments
displays its arguments
find pathname..directive..
search for files in hierarchy
processes each file beneath specified directory pathnames, applying specified directive until it encounters directive whose result is false.
-atime n true for files last accessed n days ago
-exec execute specified command
-mtime n true for files last modified n days ago
-name file specify one or more file names
- ok command same as -exec except that find asks for yes or no confirmation before acting on file
-print display pathname of file
grep [option].. pattern [file]...
Search file for pattern
Searches for patterns in specified list of files or in standard input
Options: -c count option
-l display only list of file names containing pattern
-v display all lines not matching pattern
-y ignore case
sh file [args]...
Execute shell file
Executes commands read from a shell file
sort [-bdfntu] [+field] [-o] [file] ...
sort or merge files
Sort files Options:
-b ignore leading blanks
-d sort in dictionary order
-f fold upper and lower case characters
-n order numbers in numerical order
-tx field separator x
-u eliminate duplicate lines
-o file send output to specified file
Field Specifier: Notation +1 instructs sort to use sort key excluding first field.
spell [options] file ...
Find spelling and typing errors
Check words in file against spell's dictionary
Options: +sup.file refer to specified supplemental spelling list
tee [-a] file
Pipe fitting
Sends input simultaneously to standard output and specified file Options:-a appends to specified file
wc [file...] ...
Word count
Count words, characters and lines in specified files or standard input

Shell Syntax

manipulating standard input and output

< Redirect standard input. Takes standard input from file rather than keyboard.  
> Redirect standard output. Redirects standard output to file.  
>> Append standard output. Appends standard output to end of file.  
| Pipes connect commands by sending standard output from one command to standard input of another.  

File Name Shorthand

* Asterisk. Stands for "any sequence of zero or more characters.
? Question mark. Stands for any single character
[...] Brackets. Groups of characters within square brackets match any single character contained within brackets.

Last modified: 2008/11/13 13:05:59.831000 US/Eastern by christopher.n.deckard.1
Created: 2007/05/24 14:20:47.633000 GMT-4 by brian.r.brinegar.1.



Type in a few keywords describing what information you are looking for in the text box below.

Admin Options: Edit this Document