Unix Reference Card

UNIX Reference Card

On-Line Docuemntation

Information Systems, Rice University

May 11, 1994
Document No. UNIX 1.01

Table of Contents

On-Line Docuemntation
Anatomy of a Unix Command
Important Note about UNIX Commands
Usefule Phone Numbers

File System Manipulation
Make(or Create) Directory
Look at a file
Print a file
List Files and Directories
Change Working Directory
Directory Abbreviation
Move (or rename) files and directories
Copy Files
Remove (or Delete) files
Change File Access Permissions
History: Command Repetition
Command I/O

Process Control
Process Status
Run Command in Background: Job Control

File Operations
Search for Patterns in Files
COunting Words in a File
Compare Files
File Transfer
Compress Files
Program Compilation

User Information and Helpful Commands

Windowing Environments

Anatomy of a Unix Command

command-name -option(s) filename(s) or arguments

Example: wc -l sample

The first word of the command line is usually the command name. This is followed by the options, if any, then the filenames, directory name/names, or other arguments, if any, and then a RETURN. Options are usually preceded by a dash and you may use more than one option per command.

The examples on this reference card use bold case for command names and options and italics for arguments and filenames.

whatis command - display a one-line summary about command
man command - display on-line manual pages about command

Important Note about UNIX Commands

UNIX commands are case sensitive. Type commands exactly as shown; most UNIX commands are lower case. File and directory names can be lower, upper, or mixed case but must be typed exactly as listed.

Useful Phone Numbers

 Information Desk         -  Mudd 103 (account information)        x4682
 Consulting Center        -  Mudd 103 (software questions)      527-4983
 Operations               -  Mudd Lobby (hardware problems)     527-4989
 Computing Room           -  Mudd 101                           527-4982
 Computing Reference Area -  Mudd 101S  			527-4076
 RAVL                     -  218 Anderson  			   x5153
 RUF                      -  Mudd 107 (md 107)  		   x2298
 Ryon                     -  102 (ryonps | ryon1 | ryon2)*  	   x2293
 ME241                    -  (me241)*  				   x3615
 Abercrombie              -  A121 (aba121)*  			   x2613
 Abercrombie Lab          -  B223 (aba223)*  			   x3379
 Physics Lab                  					   x2517

* Owlnet workstation locations, laser printer names, line printer names

File System Manipulation

Make (or Create) Directory

mkdir directory-name - create a directory called directory-name

Look at a File

more filename - display the file contents one screen at a time
head filename - display first few lines of a file
tail filename - display last few lines of a file

Print a File

setenv PRINTER printer - set the default printer
lpr option filename - print file
lpq option - check status of print queue
lprm option - remove jobs from printer queue
fpr option filename - print Fortran file

options: -Pprinter - specify a printer other than the default

List Files and Directories

ls directory-name - list contents of directory
-a list all files including invisible files
-l long list - shows ownership, permission, and links
-t list files chronologically
-f append "*" to executable file name, "/" to directory name
-d list directories
-u list files using time of last access instead of time of last modification
-F mark directories with forward slash, mark executables with an @-sign.
-g lists ownership of each file or directory

pwd -display the name of present working directory

Change Working Directory

cd to change to your home directory
cd directory-name to change to another directory
cd ~ : change to home directory
cd test : change to directory test

Directory Abbreviation

~          home directory (tilde)         
~username    another user's home directory  
.          current or working directory   
..         parent of working directory    

Move (or Rename) Files And Directories

mv present-filename new-filename to rename a file
mv source-filename destination-directory to move a file into another directory

options: -i interactive mode. Must confirm file overwrites.

Copy Files

cp source-filename destination-filename to copy a file into another filename
cp source-filename destination-directory to copy a file into another directory options: -i interactive mode. Must confirm overwrites.

Remove (or Delete) File

rm filename to remove a file
rmdir directory-name to remove an empty directory

options: -i interactive mode. Prompt for confirmation.

Change File Access Permissions

chmod [ who op permission ] filename

who can be any combination of:

u (user)
g (group)
o (other)
a (all) (i.e. ugo)

op adds or takes away permission, and can be:

+ (add permission),
- (remove permission), or
= (set to exactly this permission).

permission can be any combination of

r (read)
w (write)
x (execute)

Example: chmod a+x filename - makes filename executable by everyone.

Shell Tools

Wild Cards

? single character wild card
* arbitrary number of characters

History: Command Repetition

history Display list of most recent commands.
!! Repeat the entire last command line at any point in the current command line.
!$ Repeat the last word of previous command line at any point in current command line.
!: n Repeat the nth argument from previous line at any point in current command line
!^ Repeat first argument from previous command line at any point in the current command line
! n Repeat command line n
!!:p Display previous command
!string Command beginning with string
!* Repeat all arguments to previous command.

Command I/O

> command output redirection (create new)
>> command output redirection (append)
< command input redirection (from file)
<< command input (from script or standard input)


alias alias-string command-string

Alias abbreviates a command string with an alias string. For multi-command strings, enclose commands in quotes.

Example: alias shut chmod go-rwx

To use the new aliased command shut on a file, and turn off read, write, and executable permissions for all users except yourself, type shut filename.

Process Control

Process Status

ps - display the status of the current processes


-a include information about processes owned by other users
-g display all processes
-u display user-oriented processes
-x include processes with no controlling terminals
-gx display all of your local processes

kill id-number - terminate a process owned by you
id-number (PID-Process ID) can be found by first using the ps command.

Run Command in Background: Job Control

To run a command in the background, as opposed to the more common method of running commands in the foreground, append an & to the end of a command string. Then, you can type more commands to the command prompt, or even run more commands in the background for simultaneous command execution.

Control-Z - stop (interrupt) foreground job
jobs - list of background jobs
bg - run a stopped job in the background
fg - resume stopped job in the background

File Operations

Search for Patterns in Files

grep search-string filename [filename...] to find and type out lines containing the string in a file


-v type out lines that don't contain the string (invert the search)

Counting words in a file

wc filename(s) counts the number of words, lines, and characters in a file

Compare files

diff filename1 filename2 compares contents of filename1 and filename2 on a line-by-line basis

File Transfer

mail address sends mail to user at address. address format is user@host.domain
ftp host.domain use file transfer protocol to connect to remote host computer

Type ? for commands

Compress Files

compress filename compress file and rename it filename.Z
uncompress filename.Z uncompress file and rename filename

Program Compilation

f77 filename.f FORTRAN compiler
cc filename.c C compiler
pc filename.p Pascal compiler
-o filename direct output of program to filename
-l library include library in program compilation

User Information and Helpful Commands

env Lists your environment settings
who Lists users on the local system
finger username@host.domain looks up information on an other user
whois username display real name of user
clear Clears screen
leave reminds you when you have to leave
ntalk username@host.domain talk to another user
lprloc shows names and locations of printers
stty sane resets terminal characteristics to a usable set
stty display terminal characteristics
date displays current time and date
cal year for yearly calendar
cal month-year for monthly calendar
tn3270 ricevm1 full-screen remote login to mainframe
tn3270 library full-screen remote login to Fondren Library Card Catalog. At the VM/SP screen, press the RETURN key, and then enter dial libris after the screen clears. Hit RETURN again. To exit the LIBRIS system, enter CONTROL-] (Hold down the CONTROL key, and type the close bracket character), and then enter close at the TN3270 prompt.
rlogin host.domainlog into remote host computer
telnet host.domainuser interface to a remote system
whereis commandlocate a command; display its pathname
spell filenamereport spelling errors
ispell filenameinteractive spell-checker
echo $path inspect your search path
pacinfo displays your current printing charges (IS systems only)
bc basic calculator (Control-D to exit)
du display the number of disk blocks used per directory or file
du -s display your total disk usage
quota -v display your disk quota and usage

Windowing Environments

openwin enter the Open Windows window environment (not available on X terminals)
startx enter the X window environment (not required on X terminals)

startx -m enter the Motif window environment (to enter Motif from the login window of an X terminal, type your userid, RETURN, your password and then F4)