UNIX Primer Definitions

I N D E X
Name of Command Short Description UNIX Primer
cal calendar Page 39
who who (is on system) Page 40
finger finger user(s) Page 42
talk talk to a user Page 62
man online manual Page 64
ls list directory contents Page 79
cat concatenate/display file Page 80
more show file 1 page by page Page 83
pr print to stdout Page 85
mkdir create new directory Page 199
cd change directory Page 200
pwd print working directory Page 201
rmdir remove directory Page 201
rm remove file(s) Page 203
cp copy file(s) Page 205
mv move or change filename Page 207
ln make file link(s) Page 210
cc C compiler Page 236
f77 FORTRAN compiler Page 238
pc Pascal compiler Page 240
tee splits output Page 261
jobs lists & IDs stopped & bg jobs Page 269
ps process status report Page 270
kill terminate job(s) Page 271
history prints list of last commands given Page 279
alias list or make aliases Page 285
echo echo arguments Page 291
wc word count Page 310
tail shows last part of a file Page 312
head shows head of a file (BSD) Page 312
sort sorts and merges files Page 315
uniq removes duplicated lines from a file Page 317
lpr, lpq, and lprm using the line printer Page 320
chmod change modes or permissions on files Page 324
mesg permit or deny messages from talk Page 326
time time a command Page 329
calendar a reminder service Page 331
join joins lines from two files Page 339
grep searches a file for a pattern Page 374
find searches designated files and acts upon them Page 378
sort sorts files Page 384
Sorry about not having these terms alphabetized. Also, I'm not quite finished with all the terms. It'll probably be awhile before I can get back to this project...

cal
The cal command provides a calendar for whatever year you type in after the word cal. There must be at least one space between the command and the year. The year should be in the range of 0-9999 AD. You can get the calendar for just one month by preceding the year with the number of the month, numbered from 1 to 12.

Example: To see the calendar for May 1942, type:

cal 04 1942

Options: None.

Arguments: [month] year

Select Another Term | Back to Notes Menu


The who command, when typed without an argument, tells you who is currently on the system. It gives you the user's login name, the terminal name, and the time that the user logged on. If you ask who am I, it gives you this information about yourself, and it may also tell you which UNIX system you are on. The options for the who command are not important here. If you would like more information about them, you can check the on-line manual, as described in Chapter 3.

Example: To find out who's on the system, type:

who

Options: Several.

Arguments: [am I]

Select Another Term | Back to Notes Menu


The finger When typed without an argument, the finger command provides a list of all the users on the system, giving the login name, the real name, the terminal, the idle time, the login time, and the office, if known, for each user. (This list of information constitutes the short form.)

When used with one or more names, finger provides the previous information plus information about the home directory and the shell of the named users. (This argument list of information constitutes the long form.) The finger program will search for all users whose login name or real name matches the given name.

Options: [-l, -m, -s]

-m
Causes finger to search only the login names that match the argument name(s). Thus, finger -m john will give information only about a person whose login name is john and will ignore people named john who have a different login name.
-l
Forces finger to display the long form.
-s
Forces finger to display the short form.

Arguments: [name...]

Example: To find out the login names of every user named "john," and to print just the one-line summary, type:

finger -s john

The results may look like this:

Login
jonny
buny0234
daffy
suzie
john
Name
John Grock
John Bunyon
John Duck
Susan John
Johannes Brahms
TTY
5
17
18
19
22
Idle

<Jul 4 14:14>
<Aug 2 06:02>
<Aug 22 15:23>
<Aug 17 09:42>
When
12:13
Office
ACH000

CB122

MU244

Select Another Term | Back to Notes Menu


The talk command transmits lines from your terminal to the other user's terminal. To terminate transmission, press Ctrl-c. This sends EOT to the other user. Note: To block incoming messages, use the mesg command described in Chapter 11.

Options: None.

Arguments: user loginname

Select Another Term | Back to Notes Menu


When used with no argument, the man command searches the entire on-line manual for the section containing the keyword. It then prints a description of the command similar to the printed version of the manual. To keep the screen from scrolling too much information, use Ctrl-s to stop it and Ctrl-q to restart it.

Example: To display on the screen the on-line manual explanation of the cat command:

man cat

Options: Several.

Arguments: [section]

Note: man is usually quite slow in carrying out its service, so have patience.

Select Another Term | Back to Notes Menu


The ls command will list the contents of each directory named in the argument. The output, which can be a list of both files and subdirectories, is alphabetical. When no argument is given, the current directory is listed.

Options: [-a, c, l, -F, r, s, R + others]

-a
Lists all entries, including dot entries.
-c
Lists by time of last file change.
-l
Lists in long format, giving links, owner, size in bytes, and time of last file change.
-F
Marks directories with a /.
-r
Reverses the order of the listing.
-s
Gives the size in blocks of 1024 bytes (this number may vary).
-R
Also lists each subdirectory found.

Arguments: [directory...]

Example: To list the contents of the current directory in teh order that they were created, type:

ls -c

Comments: Remember that directories contain only the names of files and subdirectories. To read information contained in a file, use cat. Note that the option letters for ls may vary from system to system. This is true for many UNIX command options.

Select Another Term | Back to Notes Menu


The cat command reads each file in sequence and writes it on the standard output (terminal). If no filename is given or if - (a hyphen) is given as a filename, cat reads the standard input (the keyboard). A Ctrl-d will terminate keyboard input. If the file is too large for a singel screen, use the Ctrl-s Ctrl-q combination to control the file information appearing on the screen, or use the more command described next.

Example: To display file2, type:

cat file2

Options: Several; not important here.

Arguments: [file...]

Comments: If no input file is given, cat takes its input from the terminal keyboard. Later in this chapter, we show that cat and redirection together are very useful. Note that the redirection operator uses the symbol >. You can use cat>file5 to create a new file called file5, and you can enter text into that file. You can use cat file2 file3>>file4 to append file2 and file3 to the end of file4.

Select Another Term | Back to Notes Menu


The more command displays the named file or files one screen at a time. Commands can be typed on a command line at the bottom of the screen to control which part of the file to display. Here is a partial list of commands:

Key Pressed Result
Spacebar
Return
d
b
h
q
Advances one screen.
Advances one line.
Advances eleven lines.
Backs up one screen.
Displays help screen.
Quits.

Example: To display the contents of the myths file, type:

more myths

Options: Several.

Arguments: [filename]

Select Another Term | Back to Notes Menu


The pr command provides prints the named file or files onto the standard output. It divides the text into 66-line pages, placing five blank lines at the bottom of the page and a five-line heading at the top. The heading consists of two blank lines; a line bearing the date, filename, and page number; and two more blank lines.

Example: To print the file myths, type:

pr myths

The heading would include a line like:

May 1 12:29 1992 myths Page 1

To format the file myths and pipe the output to the printer rather than the terminal, type:

pr myths | lpr

Options: [l+others]

-k
Sets the page lenth to k lines.

Arguments: [month] year

Select Another Term | Back to Notes Menu


The mkdir command creates a new subdirectory in the present directory.

Example:

mkdir Chapter4

This commands creates a new subdirectory called Chapter4 that exists in the directory where you entered the command. Note: You should not use a blank space in your directory names; typing mkdir Chapter 4 would create two directories. A handy convention is to name all directories starting with a capital letter.

Options: None.

Arguments: [directoryname...]

Select Another Term | Back to Notes Menu


The cd command makes the named directory your current working directory. If no directory is given, the command takes you to your home directory.

Example: This command would place you in the /urs/reggie/Foods/Carbo directory:

cd/usr/reggie/Foods/Carbo

Options: None.

Arguments: [directoryname]

Select Another Term | Back to Notes Menu


The pwd command prints the pathname of the current working directory.

Options: None.

Arguments: None.

Select Another Term | Back to Notes Menu


The rmdir command removes the named directories, providing that they are empty.

Example: This command removes the directories Budget65 and Budget66 if they do not contain any files:

rmdir Budget65 Budget66

Options: None.

Arguments: directoryname(s)

Select Another Term | Back to Notes Menu


The rm command removes each file in the argument list.

Options: -i,-r

-i
For each file on the list, whether or not to delete it; the user respons with y or n for yes or no.
-r
Deletes a directory and every file or directory in it.

Arguments: filename(s)...

Example: This command will cause UNIX to query: rm: remove rodgers? And you reply with y or n for yes or no:

rm -i rodgers

Select Another Term | Back to Notes Menu


The command cp file1 file2 creates a copy of the first file (file1) and gives it the name file2. If a file named file2 already exists, it will be replaced by the new one. the second form of the command (cp file(s)...directory) makes copies of all the files listed and places them in the named directory.

Example: This command makes a copy of the file flim and calls the copy flam:

cp flim flam

This command makes a copy of the file stormy (from the /usr/snoopy directory) and places the copy in the /urs/ruff directory:

cp/user/snoopy/stormy usr/ruff

(The pathname of the copy is /usr/ruff/stormy)

Options: i, r.

-i
Protects you from overwriting an existing file by asking you for a yes or no before it copies a file with an existing name.
-r
Can be used to copy directories and all their contents into a new directory.

Arguments: file1 file2 or file(s)...directory

Select Another Term | Back to Notes Menu


The mv command allows the user to change the name of a file. The first form of the command shown below changes the name of filename1 to filename2. However, since filenames can include the full pathname, it is possible to use the command to move a file to a new directory as shown in the second form of the command.

Example: (We assume that the user is in the /urs/flisk directory and that Hobo is a subdirectory of that directory.) This changes the name of the file mrak to mark:

mv mrak mark

The following command changes the name of the file mark (pathname /usr/flisk/mark) to /usr/flisk/Hobo/mark, thus moving the file to the Hobo directory:

mv mark Hobo

This changes the name of the file mray (pathname /usr/flisk/mark) to /usr/flisk/Hobo/mary, thus changing the directory and the tail of the pathname:

mv mray Hobo/mary

Options: -i

-i
Protects you from overwriting an existing file by asking you for a yes or no before it copies a file with an existing name.

Arguments: filename1 filename2 or filename(s) directoryname

Select Another Term | Back to Notes Menu


The ln command lets you add one or more names to an existing file, thus providing a cross-reference system. Each name located in your directory has equal priority for reading or writing to the file. However, if a file is linked to another user, generally only the originator of the file can write in it (see the chmod command).

The form ln filename1 creates a line between the current working directory and filename1. Since filename1 can include a full pathname, it is linked to a file in another directory.

The form ln filename1 filename2 is like the preceding action, except that the name of the new file is filename2.

The form ln filename(s) directoryname lets you put new filenames or links into other directories.

Example: (We will assume that the current working directory is /usr/francie/Spring and that there is a file called math in the /usr/francie directory):

This command creates the filename math in the current directory (/usr/francie/Spring) and links that name to the file called math in the francie directory. The full pathname of the new link is /usr/francie/Spring/math:

ln /urs/francie/math

This command acts the same as the previous command except that the newly created filename is trig instead of math. The full pathname of the new filename is /usr/francie/Spring/trig:

ln /usr/francie/math trig

This command puts the two filenames hist and eng from the current directory into the /usr/francie directory:

ln hist eng /usr/francie

Options: None.

Arguments: filename1 [filename2] or filename(s) directoryname

Select Another Term | Back to Notes Menu


The cc command compiles programs in the C language. If the input file is in C, its name should end in .c. If it is an object-code file, its name should end in .o. The submitted files are compiled (if necessary) to create an executable program file called a.out. An object-code file is created for each C file and is stored in a file whose name is the same as the original, expect that .c is replaced by .o. (The .o file eventually is deleted if only one program is submitted.)

Example: The following command takes a C program from the file straight.c and the object code of a previously compiled C program from the file flush.o:

cc -o poker straight.c flush.o

The C program from straight.c is compiled, and the object code is placed in a file called straight.o. The two object codes are combined along with required C routines to form an executable program called poker. Typing poker will run the program.

Options: -c, -o

-c
Suppresses the loading phase (creating a.out and forces an object file to be produced.
-o filename
Causes the executable program to be given the name filename instead of a.out.

Arguments: file(s)

Select Another Term | Back to Notes Menu


The f77 compiler compiles programs written in FORTRAN. If the program is written in FORTRAN, it should be placed in a file whose name ends in .f. If the program is in object-code form, it should be in a file whose name ends in .o. The compiler takes .f files, compiles them, and stores the object code in files of the same name, but with the .f replaced by .o. The object code and required support routines are loaded into an executable file called a.out.

Example: The following command takes the FORTRAN program in the file slop.f, compiles it, and places the object code for it in a file named slop.0:

f77 -o porker slop.f

It then takes the object code, combines it with the required FORTRAN support programs, and loads them into an executable file named porker. The program can be run by typing porker.

Options: -o, -c

-o
This option causes the executable program to be called filename instead of a.out.
-c
Suppresses the loading but still produces object files for each source.

Arguments: file(s)

Select Another Term | Back to Notes Menu


The pc command compiles programs written in Pascal. Pascal filenames should end in .p. The compiler also accepts object-code programs contained in files whose names end in .o. The object code produced for a .p file is placed in a file of the same name but with the .p replaced by .o. A complete program is assembled from all the files and is loaded along with the required system routines in to an executable file named a.out. This file can be run by typing its name and pressing Return.

Example: The following command compiles the Pascal program in mask.p and places the object code for that program in the file mask.o:

pc -o zorro mask.p sword.o

It then combines this object code with the code in sword.o and with the system code to produce a complete program which is loaded into the file zorro.

Options: [-c, -o]

-c
Suppresses the loading phase (creating a.out and forces an object file to be produced, even if only one program is compiled.
-o filename
Causes the executable program to be given the name filename instead of a.out.

Arguments: file(s)

Select Another Term | Back to Notes Menu


The tee command routes its input to the terminal and also to the named file or files.

Example: This command produces the long listing of the contents of the /usr directory. This listing is sent to the terminal screen, and it also is added to the end of the file, clutter:

ls -l /usr | tee -a clutter

Options: [-i, -a]

-i
This option ignores interrupts.
-a
This option causes the output to be added to the end of the named file.

Arguments: filename(s)

Select Another Term | Back to Notes Menu


The jobs command prints a list of stopped jobs and jobs running in the background. The format is as follows:

[1] + Stopped
[2] - Stopped
[3]   Running
vi whatamess
vi fing
ls -R / | sort -o jnk

The first column is the assigned job number enclosed in brackets. The second column contains a + for the current job and a - for the next more current job. The third column states whether the job is stopped or running in background. The final column gives the name of the job.

The job command ranks by currency. From most current to least current, the order is as follows: most recently stopped job to least recently stopped job followed by the first initiated background job to the most recently initiated background job. In the example, the user went back to [1] after stopping [2] and then stopped [1] again.

The job numbers are assigned for a given terminal; if you use two terminals simultaneously, each will have its own list of job numbers.

Options: -l

-l
This option gives a long listing that also includes the process identification number (PID). This is a unique system-wide number. Different users may have jobs with the same job number, but no two jobs have the same process ID number.

Arguments: None.

Select Another Term | Back to Notes Menu


The ps command prints information about processes, i.e., jobs currently in the system. The output consists of the process identification number (PID), the terminal (TT), CPU time used (TIME), the state of the process (STAT), and the command (COMMAND). The PID is a number uniquely assigned to the process. The state is described by a four-letter sequence. The first letter can be R (for running), T (for stopped); P, D, or S (for various states of temporary inactivity); or I (for idle). The other three letters relate to more technical matters; the interested user should refer to the online manual.

Options: [-a, -x]

-a
This option displays ps information for all terminals, not just the user's.
-x
This option causes ps to report processes, such as the login shell, that were not started at the terminal.

Arguments: None.

Select Another Term | Back to Notes Menu


The kill command terminates the specified job. You can specify the job either by the job number assigned by jobs or with the process identification number (PID) given by ps or jobs -l. The format when using a job number n is:

kill number

Example: Suppose the job spell Essay > err & has job number 3 and a PID of 3492. You can terminate the job with either:

kill %3

or

kill 3492

Options: -9

-9
This is a "sure kill" which can be used if the ordinary kill fails. This actually is a special case of a more general option.

Arguments: job number or process ID

Select Another Term | Back to Notes Menu


The history command prints a list of the last n commands or events run by the C shell. To set n in the .cshrc file, add the line:

set history=n

The history list can also be used to substitute for commands using the ! symbol as shown next.

Identifying commands or events:


!n
Command number n from the history list.
!-n
The nth command before the present one.
!c
The most recent command beginning with the character c.
!?pat?
The most recent command containing the pattern pat.


Identifying words within an event; the first word is number 0:

:n
The nth word in an event.
:^or^
Same as :1
$ or $
The last word in an event.
:n1-n2
The n1 through n2 words.
^-$
Words 1 through the last word.
*
Words 1 through the last, or no word at all if there is no word 1.


Special notations:

!!
The preceding command line.
!
The preceding command line (must be followed by a word identifier).
!*
The options and arguments, if any, of the preceding command.

Examples:

This command repeats the previous command:

!!

This command causes event 5 on the history list to run:

!5

This command is run, substituting ls -l for ls:

^ls^ls -l

The command more is run on history event 5, from word 3 to the end of event 5:

more !5:3-$

Note that there are several modifiers that you can add to history substitutions. They consist of letters or symbols preceded by a colon. We'll leave it to you to investigate the online manual for details; see the sections on csh and newcsh. Most of the modifiers are more useful as components of UNIX programming than as casual aids.

Options: None.

Arguments: None.

Select Another Term | Back to Notes Menu


alias
The alias command prints a list of aliases. To make new aliases, use the second form given below. Permanent aliases can be kept in the .cshrc file. To remove aliases, use the third form.

Name
Options
Arguments
Example:
alias
None.
None.
(N/A)
alias
None.
abbreviation command
This command teaches UNIX a new name for the ls command:
alias list ls
unalias
None.
abbreviation

This command "turns off" the alias list that was set for ls:
unalias list

For more details on using alias, see the text examples or the on-line manual discussion under csh. (This section of the manual is about 20 pages long with less than one page discussing alias.

Select Another Term | Back to Notes Menu


echo
The echo command writes its arguments on the standard output. Without arguments it produces an empty line.

Example:

% echo say New York unique 10 times fast
say New York unique 10 times fast
%

Options: None.

Arguments: [any string of characters]

Select Another Term | Back to Notes Menu


wc
The wc command is actually a counting program. By default, it works in the -lwc option, counting the lines, words, and characters in the named files. If more than one file is given, wc gives the counts for each file plus the combined totals for all files. If no file is given, wc uses the standard input - the terminal. In this case, you should terminate the input with a Ctrl-d. Multiple options should be strung together on the same hyphen.

Example: This command would count the nmber of words in the file essay:

wc -w essay

Options: [-lwc]

Arguments: [filename(s)]

Select Another Term | Back to Notes Menu


tail
The tail command shows the tail end of a file. By default, it delivers the last 10 lines. The tail command will work with only one file at a time.

Example: The following command prints the last 20 lines of the file gate:

tail +30 gate

Options: [+/-number]

+number
Start number from the beginning.
-number
Start number from the end.
lbc
Indicates whether number is to be counted in lines (l), blocks (b), or characters (c). Option l is assumed if no letter is given.

Arguments: filename

Select Another Term | Back to Notes Menu


head
The head command shows the first 10 lines of the named files, unless the number option specifies a different number of lines.

Example: The following command prints the first 15 lines of the file hunter:

head -15 hunter

Options: [-number]

-number
For number, substitute the number of lines you wish to have printed.

Arguments: filename(s)

Select Another Term | Back to Notes Menu


sort
The sort command sorts and merges the lines from the named files and sends the result to the screen. In the default mode, lines are sorted by the machine-collating sequence, which is an extended alphabetical order encompassing letters, digits, and other symbols. Capital letters are sorted seperately from small letters.

Example: The following command would sort the lines of the file grabbag:

sort -fr -o sortbag grabbag

Capitalization will be ignored by teh sorting process, and the lines will be in reverse alphabetical order. The results will be stored in teh file sortbag.

Options: [-d, -f, -n, -0, -r]

-d
"Dictionary" order, using only letters, digits, and blanks to determine order.
-f
Ignore the distinction between capital and lowercase letters.
-n
Sort numbers by arithmetic values instead of by first digit.
-o filename
Place the output in a file called filename instead of on the screen. The name can be the same one as one of the input names.
-r
Sort in reverse order.

Arguments: filename(s)

Select Another Term | Back to Notes Menu


uniq
The uniq command reads the input file, compares adjacent lines, and prints the file minus the repeated lines. If a second filename is given, the output is placed in that file instead of on the screen.

Example: The following command would scan the file ioulist for lines that appear more than once consecutively. One copy of each such line would be placed in the file urgent:

uniq -d ioulist urgent

Options: [-u, -d, -c]

-u
Prints only those lines that have no duplicates. That is, a line that appears two or more times consecutively, in the original file, is not printed at all.
-d
Prints one copy of just the lines with duplicates; that is, unique lines are not printed.
-c
Prints the usual output, but procedes each line with the number of times that it occurs in the original file.

Arguments:
inputfile
[outputfile]

Select Another Term | Back to Notes Menu


Last update: Tuesday, June 30, 1998 at 1:22 AM.