Redirection of data allows UNIX programs to be combined to make
tasks easier.
>
This symbol will channel the output of a program, which would normally
go to the screen, to a file. If the distination file already existed,
it will be overwritten.
ps -aef > tempfile lists all current processes into file 'tempfile'
finger > test results of 'finger' go to file 'test'
cat fileA fileB > bigfile
Catenates fileA and fileB into bigfile,
(without altering fileA or fileB).
>>
This symbol is similar to the > but it will append rather than overwrite.
date >> log adds today's date to end of file 'log'
2>
This is used to capture error messages from programs.
cc test.c 2> errors tries to compile test.c, errors go to file
<
This is used to make a file the input for a program. The program will
be able to read the file in through its stdin.
mail webmaster@dxdt.com < testfile
sends testfile to address
|
This symbol (the 'pipe') is one of the most useful in UNIX, capable
of chaining whole sets of commands together. The output of each
program is fed as input into the next program. For example:
ps -aef | more shows all processes, one screen at a time
who | grep dmtc shows who is logged on as dmtc
And of course, these can be combined in many more ways:
ps -aef | grep dmtc | head 3 >> log
(this command should show the first three processes by dmtc and save them
to the file 'log').
*
Not really a command, this is a wildcard that will match any file. Use
this to specify multiple files:
rm * Delete everything in this directory
ls *.c Show everything with .c at the end
grep hello myfile*.c Searches in files myfile1.c, myfile2.c, etc.
touch temp* Update time on all files starting with 'temp'
;
The semicolon can be used to enter several commands on one line, as in:
uptime;finger;exit These commands will be executed in succession,
with no prompt or delay between them.
This is similar to the ampersand '&', as multiple commands can be started
in the background simultaneously and separated like this:
gzip *.c & rm *.o &