Unix Command Dictionary
Unix Command Dictionary
Table of Contents
• UNIX Log In and Out Commands.
• UNIX Information Commands.
• UNIX C Language Commands.
• UNIX makefile Commands.
• UNIX Directory Commands.
• UNIX File Commands.
• UNIX Pipe and Redirection Commands.
• UNIX Mail Commands.
• UNIX Control-Key Commands.
• UNIX Terminal Environment Commands.
• UNIX Process Commands.
• UNIX Editor Commands.
• The ex Editor.
• The vi Editor.
will yield information in an almost readable format during a IBM Telnet session. The
problem is that you have both UNIX and CMS paging the output. You respond to the
UNIX paging prompt `:' with a `(CR)' return for a new page, `d (CR)' for a short new
page, u (CR)' for a short page up (back), or `q (CR)' to quit. For the CMS paging
prompt `holding', respond with the designated `Clear-key'. If you are using IBM
Telnet, then `man [command]' usually produces poor output for the head of the
display. The version `man -blou [command] (CR)' should remove underscoring and
other backspacing for printing at UIC, but does not work completely. For a quick
overview of a command try the `-q' quick option:
Alternatively,
is useful for redirecting the output to a file that can later be transfer back to CMS for
printing (e.g. by `printdoc'). The UNIX no paging `-r' option does not work in a CMS
session, so the CMS user has to press both the `Return-key' for a new UNIX `man'
page or the `Clear-key' for a new CMS page depending on the odd UNIX prompt or
the CMS ``HOLDING'' prompt, respectively.
This abridged UNIX dictionary is only intended to be a short enough list to get you
started without being bewildered by the enormous UNIX manuals, but with enough
commands to be able to do something useful. For more information use the `man'
command or refer to some of the UNIX texts. UNIX is a trademark of Bell
Laboratories.
The format is
along with a carriage return `(CR)' for each command. DO NOT FORGET that
almost all UNIX commands must be in lower case. Do not attempt to learn all of this
at once, but read some of it and try it out at an actual computer session.
man [-option] [command] (CR) : Manual or UNIX help command. The usual
quit sequence `q (CR)' can be used to quit long UNIX `man' listings, `(CR)' is
used for new `man' pages. During a IBM Telnet session the `Clear-key' is
needed for new CMS pages that are not the same as the `man' pages.
Otherwise `d', `q' or `Ctrl-c' should work for UNIX like access.
cc -hnoopt -o run [file].c (CR) : Compiles source [file].c, using the standard
C compiler `scc3.0' and producing an executable file named run without scalar
optimization or vector optimization while `hopt' enables scalar and vector
optimization, Some other optimization related options are `-hinline' for
inlining while `-hnone' is the default no inlining, `-hnovector' for no vector
(vector is the default), and `-h listing' for a pseudo-assembler (CAL) listing.
Some standard C options are `-htask3' for automatic parallelization
(autotasking in crayese) and `-hvector3' for more powerful vector
restructuring. Other `-h' suboptions are `ivdep' for ignore vector dependence,
`-hreport=isvf' generates messages about inlining (i), scalar optimization (s)
and vector optimization (v), and `-hreport=isvf' writes same messages to
`[file].v'. A commonly used form will be
#include <stdio.h>
#include <fortran.h>
#define fortran
main()
{
fortran void SUB();
float x = 3.14, y;
SUB(&x, &y);
printf("SUB answer: y = %f for x = %f\n", x, y);
}
make [-options] [step-name] (CR) : Makes the files [files] according to the
template in the `makefile'. See the examples `makefile *' on the `getdisk
hanson' disk in CMS, e.g., the file `makefile.unicos_2':
mkdir [name] (CR) : Makes a directory or file group name [name]; e.g.
`mkdir dirpgm (CR)' make the directory called `dirpgm'.
pushd [name] (CR) : Pushes from the working directory to the directory
[name] keeping the sequence of directories in a buffer for `popd'.
popd (CR) Pops back up to the prior directory, if `pushd' was used before. For
this reason, `pushd' and `popd' are more useful than the regular change
directory command `cd'.
pwd (CR) : Displays working directory; `echo $HOME (CR)' displays the
home directory.
rmdir (CR) : Removes or erases empty directory. You must first use `rm *' to
empty the file.
ls [string].* (CR) : Lists all current files with prefix [name]. Examples of
other forms are `ls *[string] (CR)' or `ls *[string]* (CR)' or `ls
*[string1]*[string2]*'.
cat [file1] ... [fileN] (CR) : Lists content of N (N .le. 1) argument files
catenated. Use `cat [file1] ... [fileN] > [fileM] (CR),' to catenate and store the
N files in `[fileM]'.
more [file] (CR) : Displays file in half pages of 11 lines; use `q (CR)' for
quitting; use `d' for 11 more lines or `u' to go back up 11 more lines; similarly,
`f' and `b' produce full pages forward and backwards, respectively; while
`/[string]?[string]
Caution: works poorly with TELNET from CMS. Use `cat [file] (CR)'
with the CMS Clear-key instead.
mv [file1] [file2] (CR) : Renames file `[file1'] as file `[file2]', i.e., moves one
file to another.
grep `[str]' [file1] (CR) : Searches for string [str] in file [file1]. ``cat [file1]
[file2] | grep `[string]' (CR)'' searches for the pattern `[string]' in the
catenated files. Note the different string pattern, with the standard single
quote used within the command to enclose the target string when it is more
than one word.
diff [file1] [file2] (CR) : Displays the difference between files `[file1]' and
`[file2]'.
chmod [mode] [file] (CR) : Changes the read, write and execute
permissions for the file (or files) `[file]' according to the `[mode]' which
has form `[[who] [operator] [permission]]'; `[who]' is `u' for the user, `g'
for the defined group', `o' for others and `a' = `ugo' for all; `[operator]' is
`+' to add and `-' for remove; `[permission]' is `r' for read, `w' for write
and `x' for execute; current permissions are displayed with the default
long list command `ls [file] (CR)' in the first field or the sample forms
`drwxrwxr-x' or `-rwxr--r--' with the first character denoting a directory
if `d' is present, a `--' denotes no permission, with each remaining subfield
of three denoting the user, group and others, respectively; for example
`chmod go-wx *' removes write and execute permissions in the current
directory for all but the user, `chmod u+w [file]' adds write permission to
only the user; the user may be queried about removing protection for his
own files.
history (CR) : Lists the history of the most recent commands entered.
![string] (CR) : Repeats execution of the last command beginning with the
pattern [string] in the `history' listing.
![string]:p (CR) : Repeats listing of the last command beginning with the
pattern `[string]' in the `history' listing, but does not execute it. You can
return (CR) to execute or you can modify it by the command that follows
immediately below.
mail (CR) : Shows user`s mail; use the subcommand `t [N](CR)' to list
message number `[N]' , `s [N] mbox (CR)' to append message `[N]' to your
mailbox `mbox' file or `s [N] [file](CR)' to append `[N]' to another file; `e
[N] (CR)' to edit number [N] or look at a long file with `ex' {see Section on
`EX' below}; `v [N] (CR)' to edit number [N] or look at a long file with
`vi'; `d [N] (CR)' deletes {your own mail!} `[N]'; `m [user] (CR)' permits
you to send mail to another account `[user]'; a `~m [N] (CR)' inside the
message after entering a subject, permits you to forward message `[N]' to
`[user]', `\d (CR)' to end the new message {see the send form below;`x'
quits `mail' without deleting {use this when you run into problems}; and
`q (CR)' to quit.
mail [user] (CR) : Sends mail to user `[user]'; the text is entered
immediately in the current blank space; carriage return to enter each
line; enter a file with a `~r[filename] (CR)'; route a copy to user `[userid]'
by `~c[userid] (CR)'; enter the `ex' line editor with `~e (CR)' or `vi' visual
editor with `~v (CR)' (see Sections on EX and on VI) to make changes on
entered lines, exiting `ex' with a `wq (CR)' or `vi' with a `:wq' (CR)'; exit
`mail' by entering `\d (CR)'. {A bug in the current version of Telnet does
not allow you to send a copy using the `cc:' entry. However, ending with
the ``hack'' `\d [user_cc] (CR)' should get a copy to user `[user_cc]'.}
UNIX users should not encounter IBM Telnet problems.
Ctrl-h : Erase or backspace over character; note the CTRL-key and h-key
must be simultaneously pressed.
Ctrl-q : Quiet character {else for IBM Telnet use `\q (CR)'}.
Ctrl-u : Kill character {else for IBM Telnet use `\u (CR)'}.
Ctrl-w : Word erase character {else for IBM Telnet use `\w (CR)'}.
tset -m :h19b (CR) : Sets terminal type to Heathkit or Zenith type `h19b'.
WARNING: Several terminal commands are given here, because you might
have to try several before you find one that works. Note that one of the
biggest problems in working with advanced, remote computers is
COMMUNICATION and that much of this local guide is intended to solve
communication problems.
stty erase \[key](CR) : Set or reset the terminal (`tty') erase key to `[key]'.
stty all (CR) : Display usual Control characters; with arguments can be
use to set terminal communication variables; also try `stty everything'.
jobs - l (CR) : Display a simple single line with currently active job status.
kill -9 [pid] (CR) : Means a ``sure kill'' of ``pid'' [pid]; this becomes
necessary when you lose control of a process or have a session aborted.
CAUTION: Aborted sessions are not uncommon so it is helpful to develop
skills of a super process (program) killer.
ex [file] (CR) : `EX' line editor. This is the preferred editor for LINE
EDIT MODE with TELNET. `:' is the `ex' prompt. `ex [file1] ... [fileN]
(CR)' is the form used for multiple files with the `n' command used to go
to the next file, rather than `q' to quit. Ex can also be used in vi with ':' as
a prefix, when vi works. `ed' is another line editor with less availability.
More details on `ex' are given in the next section.
vi [file] (CR) : Invokes the UNIX full screen editor `vi' to edit file [file];
this visual editor has a large set of subcommands. Warning: the `vi'
command will NOT work properly with the LINE MODE of CMS TELNET
and YOU WILL LIKELY GET IN A STUCK SESSION IF YOU TRY IT.
(Try to get access to a UNIX system or PC Telnet systems, such as those in
the 2249f SEL PC Lab.)
vi -r [file] (CR) : Form of `vi' used to recover `[file]' after aborted session.
Similarly, `ex -r [file] (CR)' is for an aborted `ex' session.
ex Editor
`Ex' is the UNIX line editor (`ed' is another UNIX line editor) and `vi' is the full
screen editor that is disabled by IBM TELNET. The prompt is `:', but the user
enters input at the bottom of the screen with IBM TELNET line mode. In `ex' `.'
means the current line, `$' means the last line, and `%' means the whole range of
lines `1,$'. `[L1],[L2]' denotes the range from line `[L1]' to line `[L2]'. The user
may want to do major editing on the CMS multi-line editor XEDIT and send the
file using the FTP file transfer protocol. Some students may have had experience
with this editor (or the similar `ed' editor) from EECS courses. These `ex'
commands can be used within the `vi' editor by typing a colon `:' in front of the
`ex' command, which is another reason for learning `ex' with `vi' when you have
an account where `vi' can be used.
0a (CR) : This form of the append subcommand puts you in input mode
starting with line 1, new lines are entered following a `(CR)', and input
mode is ended with a solitary or sole `.' on a line with an immediate
`(CR)', i.e., `.(CR)'. This is not the usual method for opening a new file,
but the usual way does not work correctly with the IBM Telnet and CMS
pass through.
w [file] (CR) : Save (write) or resave into the new file [file], but do not
end. If no [file] is specified, then the current file is resaved.
w! [file] (CR) : Resave (rewrite) into an old file [file], but do not end. `Ex'
will not write over an existing non-current file with the `w' command
without the `!'.
w|n (CR) : When `ex' is used on more than one file, writes the current file
and makes `ex' go to the next file. `|' puts two `ex' commands together.
set number (CR) : Number all lines; line numbers are needed for effective
use or `ex'; by putting this and other commands in your `.exrc' Ex
Resource Configuration file, the command will be operative until it is
changed.
[L1] i (CR) : Insert at line [L1]. End with a lone `.(CR)' after the last
input line. Does not work on an empty file.
[L1] a (CR) : Append after line [L1]. End with a lone `.(CR)' after the last
input line. Does not work on an empty file.
[L1] o (CR) : The UNIX open command does not work correctly with
IBM TELNET because the usual end commands do not work properly.
End with a line `.(CR)'.
[L1],[L2] co [L3] (CR) : Copy lines [L1] to [L2] to after line [L3].
[L1],[L2] m [L3] (CR) : Move lines [L1] to [L2] to after line [L3].
[L1],[L2] t [L3] (CR) : Take {copy} lines [L1] to [L2] to [L3]; destination
[L3] can not be in ([L1] to [L2]-1).
[L1],[L2] d [buffer] (CR) : Delete and yank lines [L1] to [L2] to named
buffer [buffer]. See `pu'.
[L3] pu [buffer] (CR) : Put lines from named buffer [buffer] after line
[L3]. See `ya'.
vi Editor
The UNIX full screen editor `vi' is a tightly designed editing system in which
almost every letter has a function and the function is stronger for upper than
lower case. However, a letter and its actual function are usually closely related. It
is important to remember that the `(Esc)' escape key ends most functions and a
`(Esc), (Esc)' double application certainly ends the function with the ring of a
bell. The subcommand `u' undoes the last function (presumably an error). Use
`:q! (CR)' to end with out saving, especially in hopeless situations. Use `:wq (CR)'
to resave and end {`ZZ' also resaves and ends, but will not resave if the file has
been saved in another file and no further changes have been made}, or `:w (CR)'
to only resave. The character `:' prompts the UNIX line editor `ex' which you can
think of as being embedded in `vi'. Some of the above critical `vi' subcommands
are repeated below with others. Most `vi' subcommands are not displayed when
used and do not take a carriage return `(CR)'. The fact that most keys have a
meaning both as single characters and as concatenations of several characters
has many benefits, but has disadvantages in that mistakes can turn out to be
catastrophic. {Remember that `(Esc), (Esc), u' key sequence!} {WARNING: `VI' is
disabled during an IBM Telnet session.}
(Esc) : End a command; especially used with insert `i', append `a' or
replace 'R'.
(Esc), (Esc) : Ensured end of a command with bell; press the Escape-key
twice; use it.
:set all (CR) : Display all vi options. Use this ex command when your
initial vi session is poor. Customized options are placed in the `.exrc' ex
resource configuration profile.
:w (CR) : Save or resave the default file being edited, but do not end.
:w [file] (CR) : Save into a new file [file], but do not end.
:w! [file] (CR) : Save or resave into an existing file [file], but do not end.
:q! (CR) : Quit vi without saving, living the file as it was in the last save.
:wq (CR) : Save the default file being edited, and quit.
ZZ : Save the edited file, provided not changes have been made since the
last save of the edited file to any file, and quit `vi'. {Warning: if you just
saved the edited file into any other file, the file will NOT be resaved. `:wq
(CR) is much safer to use.}
k = up
^
|
h = left <-- --> right = l
|
v
j = down
each take a number prefix that moves the cursor that many times.
(CR) : moves cursor a line forward; `+' also does.
[L]G : Go to line [L]. `1G' moves the cursor to the beginning of the file
(BOF).
G : Go to the last line just before the end of file (EOF) mark. `$G' does
the same thing.
/[string] (CR) : Find the next occurrence of `[string]' forwards. Use `n' to
repeat, or `N' to search backwards.
. : Repeat last change. This is best used along with the repeat search `n' or
`N'.
o[string](Esc) : Opens a new line below the current line for insertion of
string `[string]'; end with `(Esc)' or `(Esc), (Esc)'; use for POWER
TYPING input for an old or new file; `O[string](Esc)' opens a new line
above the current line for insertion.
w : Move cursor to the beginning of the next word. `[N]w' moves the
cursor `[N]' words forward. `[N]b' moves it `[N]' words backward. `[N]e'
moves it to the end of the word.
"b[N]Y : Yank [N] lines starting with the current line to the buffer labeled
b; the double quote {"} is used to avoid an id conflict with subcommand
names; any letter other than `x' can be used to name the buffer; safer
than the line yank `yy' because it is very easy to accidentally change the
default buffer.
"b[N]dd : Deletes [N] lines starting with the current line to the buffer
labeled `b'.
"bp : Put back lines from the buffer labeled `b' after or below the cursor;
use after a yank or delete to a labeled buffer to move groups of lines from
one location to another.
"bP : Put back lines from the buffer labeled `b' before or above the
cursor; use after a yank or delete to a labeled buffer to move groups of
lines from one location to another.
Some `ex' editor commands that are useful in `vi' follow the `:' prompt. See the
previous section on `ex' for more commands.
:[L1],[L2] m [L3] (CR) : Move lines `[L1]' to `[L2]' to after line `[L3]'.
• Home
• Menus
• Glossary
• Help
Text size:
Commands
cp date df du
mv ps pwd rm
cal
This command will print a calendar for a specified month and/or year.
To show this month's calendar, enter:
cal
cal 2008
cal 6 1970
cat
This command outputs the contents of a text file. You can use it to read brief
files or to concatenate files together.
cat myfile
Because cat displays text without pausing, its output may quickly scroll off
your screen. Use the less command (described below) or an editor for
reading longer text files.
For more, see In Unix, how do I combine several text files into a single file?
cd
This command changes your current directory location. By default, your Unix
login session begins in your home directory.
cd myfiles
cd /home/dvader/empire_docs
cd /
cd
chmod
To allow yourself to execute a file that you own named myfile, enter:
To allow anyone who has access to the directory in which myfile is stored
to read or execute myfile, enter:
You can view the permission settings of a file using the ls command,
described below.
Note: Be careful with the chmod command. If you tamper with the directory
permissions of your home directory, for example, you could lock yourself out
or allow others unrestricted access to your account and its contents.
For more, see In Unix, how do I change the permissions for a file?
cp
This command copies a file, preserving the original and creating an identical
copy. If you already have a file with the new name, cp will overwrite and
destroy the duplicate. For this reason, it's safest to always add -i after
the cp command, to force the system to ask for your approval before it
destroys any files. The general syntax for cp is:
cp -i oldfile newfile
cp -i /home/dvader/notes/meeting1 .
To copy a file named oldfile in the current directory to the new name
newfile in the mystuff subdirectory of your home directory, enter:
cp -i oldfile ~/mystuff/newfile
Note: You must have permission to read a file in order to copy it.
date
The date command displays the current day, date, time, and year.
date
df
This command reports file system disk usage (i.e., the amount of space
taken up on mounted file systems). For each mounted file system, df
reports the file system device, the number of blocks used, the number of
blocks available, and the directory where the file system is mounted.
To find out how much disk space is used on each file system, enter the
following command:
df
df -k
du
This command reports disk usage (i.e., the amount of space taken up by a
group of files). The du command descends all subdirectories from the
directory in which you enter the command, reporting the size of their
contents, and finally reporting a total size for all the files it finds.
To find out how much disk space your files take up, switch to your home
directory with the cd command, and enter:
du
The numbers reported are the sizes of the files; on different systems, these
sizes will be in units of either 512 byte blocks or kilobytes. To learn which is
the case, use the man command, described below. On most systems, du -k
will give sizes in kilobytes.
find
The find command lists all of the files within a directory and its
subdirectories that match a set of conditions. This command is most
commonly used to find all of the files that have a certain name.
To find all of the files named myfile.txt in your current directory and all of
its subdirectories, enter:
To look in your current directory and its subdirectories for all of the files that
end in the extension .txt , enter:
On some systems, omitting the final / (slash) after the directory name can
cause find to fail to return any results.
jobs
This command reports any programs that you suspended and still have
running or waiting in the background (if you had pressed Ctrl-z to suspend
an editing session, for example). For a list of suspended jobs, enter:
jobs
Each job will be listed with a number; to resume a job, enter % (percent
sign) followed by the number of the job. To restart job number two, for
example, enter:
%2
This command is only available in the csh, bash, tcsh, and ksh shells.
kill
Use this command as a last resort to destroy any jobs or programs that you
suspended and are unable to restart. Use the jobs command to see a list of
suspended jobs. To kill suspended job number three, for example, enter:
kill %3
Now check the jobs command again. If the job has not been cancelled,
harsher measures may be necessary. Enter:
kill -9 %3
Both less and more display the contents of a file one screen at a time,
waiting for you to press the Spacebar between screens. This lets you read
text without it scrolling quickly off your screen. The less utility is generally
more flexible and powerful than more, but more is available on all Unix
systems while less may not be.
less textfile
The less utility is often used for reading the output of other commands. For
example, to read the output of the ls command one screen at a time, enter:
ls -la | less
In both examples, you could substitute more for less with similar results. To
exit either less or more, press q . To exit less after viewing the file, press
q .
Note: Do not use less or more with executables (binary files), such as
output files produced by compilers. Doing so will display garbage and may
lock up your terminal.
lpr and lp
To print a file named myfile on a printer named lp1 with lpr, enter:
To print the same file to the same printer with lp, enter:
lp -dlp1 myfile
For more, see In Unix, how do I print files and list or remove print jobs?
ls
This command will list the files stored in a directory. To see a brief, multi-
column list of the files in the current directory, enter:
ls
To also see "dot" files (configuration files that begin with a period, such as
.login ), enter:
ls -a
To see the file permissions, owners, and sizes of all files, enter:
ls -la
If the listing is long and scrolls off your screen before you can read it,
combine ls with the less utility, for example:
ls -la | less
man
This command displays the manual page for a particular command. If you
are unsure how to use a command or want to find out all its options, you
might want to try using man to view the manual page.
man ls
man man
If you are not sure of the exact command name, you can use man with the
-k option to help you find the command you need. To see one line
summaries of each reference page that contains the keyword you specify,
enter:
man -k keyword
Replace keyword in the above example with the keyword which you want to
reference. Also see In Unix, what is the man command, and how do I use it
to read manual pages?
mkdir
mkdir mystuff
mv
This command will move a file. You can use mv not only to change the
directory location of a file, but also to rename files. Unlike the cp command,
mv will not preserve the original file.
Note: As with the cp command, you should always use -i to make sure
you do not overwrite an existing file.
To rename a file named oldname in the current directory to the new name
newname, enter:
mv -i oldname newname
mv -i newhw/hw1 oldhw
If, in this last operation, you also wanted to give the file a new name, such as
firsthw, you would enter:
mv -i newhw/hw1 oldhw/firsthw
ps
ps -alxww
ps -elf
For more information about ps refer to the ps man page on your system.
Also see In Unix, what do the output fields of the ps command mean?
pwd
This command reports the current directory path. Enter the command by
itself:
pwd
rm
This command will remove (destroy) a file. You should enter this command
with the -i option, so that you'll be asked to confirm each file deletion. To
remove a file named junk, enter:
rm -i junk
Note: Using rm will remove a file permanently, so be sure you really want to
delete a file before you use rm.
rm -rf oldstuff
Note: Using this command will cause rm to descend into each subdirectory
within the specified subdirectory and remove all files without prompting you.
Use this command with caution, as it is very easy to accidently delete
important files. As a precaution, use the ls command to list the files within
the subdirectory you wish to remove. To browse through a subdirectory
named oldstuff, enter:
ls -R oldstuff | less
rmdir
Note: The directory you specify for removal must be empty. To clean it out,
switch to the directory and use the ls and rm commands to inspect and
delete files.
set
To see the status of all settings, enter the command without options:
set
If the output scrolls off your screen, combine set with less:
set | less
The syntax used for changing settings is different for the various kinds of
Unix shells; see the man entries for set and the references listed at the end
of this document for more information.
vi
This command starts the vi text editor. To edit a file named myfile in the
current directory, enter:
vi myfile
The vi editor works fairly differently from other text editors. If you have not
used it before, you should probably look at a tutorial, such as How do I use
the vi text editor? Another helpful document for getting started with vi is A
quick reference list of vi editor commands.
The very least you need to know to start using vi is that in order to enter text,
you need to switch the program from command mode to insert mode by
pressing i . To navigate around the document with the cursor keys, you
must switch back to command mode by pressing Esc. To execute any of the
following commands, you must switch from command mode to ex mode by
pressing : (the colon key): Enter w to save; wq to save and quit;
q! to quit without saving.
w and who
The w and who commands are similar programs that list all users logged into
the computer. If you use w, you also get a list of what they are doing. If you
use who, you also get the IP numbers or computer names of the terminals
they are using.
Also see: