2.0 UNIX Concepts

UNIX Philosophy: (a) Each program/command should be a tool that does only one thing and does it well. (b) A new tool should combine existing tools, not write new ones whenever possible. (c) The design of UNIX is based on: you are assumed to know what you are doing.

Standard Data Streams in UNIX:
Standard input = Terminal Keyboard;
Standard output, Standard error = Terminal Screen

Definition: Redirection = Redefining the default standard input or output or error destination to a device or a file.

For the duration of a Unix command you can do:

Redirected Standard input  <  example:        $ mail rkatz < messagefile

Redirected Standard output >  example:	      $ date > save.date

Redirected Standard error  2> example:	      $ cat -z junk 2> errorfile

Appended Redirected output >> example:	      $ cal 2003 >> save.date

Appended Redirected error 2>> example:	      $ ls -z 2>> errorfile

Note: When you learn how to use a new program/command, do not memorize every detail. Learn (1) What the program can do for you; (2) The basic details; (3) where to look for help when you need it.

Commands to learn (See online man or info pages):

date(1)			- print or set the system date and time

ls, l, ll (1) 		- list contents of directories

cal(1)			- displays a calendar

cat(1)			- concatenate, copy, and print files on Standard Output

more(1)			- file perusal filter for crt viewing

less(1)  		- opposite of more (but the same)

[pg(1)			- file perusal filter for soft-copy terminals]* [not on Linux]

lp(1)           	- line printer (print files command)

echo(1), [print]        - display (or output) arguments

printf(1)       	- format and print arguments

Examples of Commands in use:

$ cal > this.month

$ cat this.month

$ # when you type the following 2 commands type some text on several
$ # lines and notice any response. Type <Ctrl-D> to get your prompt back

$ cat

$ cat > new.file

$ cat oldfile1 oldfile2 >> new.file

$ # cp cat (copy cat):

$ cat sourcefile > targetfile vs $ cp sourcefile targetfile

$ cat < olddata > newdata

$ # What does this pair of commands do?

$ cp /dev/null newdata

$ cat /dev/null > newdata

$ #What does this command do?
$ cat catfood

$ #trivial editors
$ echo "first line of file" > newerfile
$ echo "2nd line of file" >> newerfile
$ echo "3rd line of file" >> newerfile
$ cat > newerfile
first line of file
2nd line of file
3rd line of file
etc.
$ cat newerfile
first line of file
2nd line of file
3rd line of file
etc.
$

Questions? Robert Katz: rkatz@ned.highline.edu
Last Update June 17, 2003