PAGEFLOP
FORWARD
SELECTOR
SELAGAIN
WRONGSEL
YOUR SELECTION IS NOT IN THE 0 - #SELIMIT RANGE Please Try Again
AANVANG
Copyright CourseWare Technologies Inc., 1985-88.
Lesson - 2
UNIX COMMANDS
MENU
UNIX Commands|Topics to Learn|2-0|10,50
# Topic
--- -------
1 - UNIX Commands and Utilities
2 - UNIX Command Format
3 - User Information Commands
4 - Text Processing Utilities
5 - File Management Utilities
6 - Lesson Review
0 - Return to the Main Menu
P1
UNIX Commands|Commands and Utilities|2-1.1|14,50
A UNIX system provides over 300 public commands.
These include:
* programs shared by many users
* your own programs, and
* commands internal to the shell.
In this course we will discuss:
* command format,
* user information commands,
* text processing utilities, and
* file management utilities.
P2
UNIX Commands|Command Format|2-2.1| 12 , 49
The first word in a command line is the
name of the command.
The command syntax varies from one command
to another.
SOME EXAMPLES:
command_name <CR>
command_name filename <CR>
command_name option(s) <CR>
command_name option(s) filename <CR>
P3
UNIX Commands|User Information Commands|2-3.1|16,60
Users need information about the system, such as
information about files stored in directories, the number
of users logged on to the system, what processes are
running, the amount of space available on the disk, etc.
Some commands that provide this information are:
pwd - prints the pathname of the user's current
working directory
ls - lists file names in the current directory
file file_name - provides information on the
type of file file_name is.
P4
UNIX Commands|User Information Commands|2-3.2| 10 , 69
who - displays the names of users on the system along
with their terminal identification and the time
they logged in.
du - displays a summary of disk usage.
ps [options] - prints information about active processes
(process status). Without options,
information is printed about processes associated
with the current terminal.
P5
UNIX Commands|User Information Commands|2-3.3| 8 , 50
kill processid - terminates the process whose
id is processid.
nohup command - runs command immune to
hangups or quits. Uses default files for
writing results.
nice command - runs the command at low priority.
P6
UNIX Commands|Text Processing Utilities|2-4.1|14,62
Text processing is one of the strongest virtues of UNIX.
Often UNIX systems are chosen for their strong word
processing capabilities.
Advanced text processing utilities include:
* nroff * tbl * m4 * yacc
* troff * eqn * lex
This section deals with simpler text processing commands.
P7
UNIX Commands|Text Processing Utilities|2-4.2|12,54
The cat program will display a file from beginning
to end without stopping. For example,
cat /etc/passwd will display the content of the
password file that holds user names, user id's,
group id's and the encrypted passwords.
cat chapt_1 chapt_2 chapt_3 > book will write
the contents of the files chapt_1, chapt_2 and
chapt_3 into the file book.
P8
UNIX Commands|Text Processing Utilities|2-4.3|5,54
If you want to print a file with pagination and
a header at the top of the page, use the pr program.
For example,
pr chapter_7
P9
UNIX Commands|Text Processing Utilities|2-4.4|9,54
The lpr command sends its output to the system's
off-line printer. For example, the command
ls *.c | pr | lpr
will find all of the files whose names end in .c and
pass them to the pr program to be paginated. The
output from the pr program is then passed to the
printer for output on paper.
UNIX Commands|Text Processing Utilities|2-4.4|15,54
The lpr command sends its output to the system's
off-line printer. For example, the command
ls *.c | pr | lpr
will find all of the files whose names end in .c and
pass them to the pr program to be paginated. The
output from the pr program is then passed to the
printer for output on paper.
The nl command (AT&T's versions) will print a
file with each line numbered. For example:
nl chapter_4
P10
UNIX Commands|Text Processing Utilities|2-4.5|7,54
You can find the differences between two files
by using the diff command. For example, the command:
diff chapter1.old chapter1.new > differ
will compare the two files line for line and place the
lines that differ in the file differ.
P11
UNIX Commands|Text Processing Utilities|2-4.6|8,54
You can sort data in a file by specifying
various ordering with sort command. For example,
sort -fr filename
will fold (change to lowercase) all uppercase
letters in the file filename and then sort all
of the lines in decreasing order (-r for reverse).
P12
UNIX Commands|Text Processing Utilities|2-4.7|8,50
The command that lets you cut out certain
parts of a file is cut. For example:
cut -c1-60 userdata > user_id
takes the first 60 characters from every line in
the file userdata and places them into a file
called user_id.
P13
UNIX Commands|Text Processing Utilities|2-4.8|7,57
The command that lets you combine files with
various column arrangements is paste. For example:
paste flight_no airline > schedule
pastes from left to right contents of files flight_no
and airline and writes the result to file schedule.
P14
UNIX Commands|Text Processing Utilities|2-4.9|7,57
The command that helps you find a specific text
pattern in a file is grep. For example:
grep error_check *.c
looks in all files whose names end in .c for the words
error_check and displays them on the standard output.
P15
UNIX Commands|Text Processing Utilities|2-4.10|8,56
One of the most useful commands for preparing
manuscripts or formal letters is spell, which checks
for spelling errors in the specified file. For example:
spell < lect_10 > wrong_spell
will find all of the misspelled words in lect_10 and
write the list in a file called wrong_spell.
P16
UNIX Commands|Text Processing Utilities|2-4.11|7,54
Use the command tee to redirect the output to
a file and to see it on the terminal at the same time.
spell chapt_10 | tee err_10
will write the list of misspelled words in the file
chapt_10 to the file err_10 and to the user's terminal.
P17
UNIX Commands|File Management Utilities|2-5.1| 10 , 50
File management utilities help one to:
* delete files
* rename files
* copy files
* change file ownership
* change file protection
* create directories
* remove directories
P18
UNIX Commands|File Management Utilities|2-5.2|8,54
To delete ordinary files, the utility rm is
used. For example:
rm -fr *.c
silently removes all files ending in .c from the
current directory as well as from all of the
directories below the current one.
P19
UNIX Commands|File Management Utilities|2-5.3|6,54
To rename/move a file use the mv command:
mv chapt3 ../book_3
moves the file chapt3 from the current directory
into the parent directory and renames it book_3.
P20
UNIX Commands|File Management Utilities|2-5.4| 6 , 55
You can make copies of files with the command cp.
For example:
cp chapt4 ../book_4
makes a copy of the file chapt4 in the current
directory and calls it book_4 in the parent directory.
P21
UNIX Commands|File Management Utilities|2-5.5|8,54
The ownership of a file may be changed by the
owner or a superuser with the command chown. For
example:
chown johnson lect_10
makes the user whose login name is johnson the owner
of file lect_10.
P22
UNIX Commands|File Management Utilities|2-5.6|7,54
The protection of a file may be changed with the
command chmod. For example:
chmod go-w data_file
deletes the write permission of the group and others
on the file data_file.
P23
UNIX Commands|File Management Utilities|2-5.7| 7 , 56
You can establish a second name or another link
for a file with a command ln. For example:
ln chapter7 chapter71
establishes another name for referencing the file
chapter7.
P24
UNIX Commands|File Management Utilities|2-5.8| 11 , 51
Finally the command that allows you to create
directories is mkdir, and the command for removing
empty directories is rmdir. For example:
mkdir tst_dir
creates the directory tst_dir and
rmdir tst_dir
removes the directory tst_dir, if it is empty.