What Is A File Unix
What Is A File Unix
What is a stream?
In the discussion of files, we learned that a file is a sequence of characters stored on
a disk.
The Unix operating system defines a slightly more general concept:
A stream is any sequence of characters.
An input stream can come from a file, from a keyboard, from a process, or
from any other device (such as a scanner or a network).
An output stream can be destined for a file, for a display, or to any other
device (such as a printer or a network)
What is a process?
In general, a Unix process is one execution of a program or command.
Every process transforms one or more input streams into one or
more output streams.
For example, if you use a word processor to produce a document, the word
processor is converting your keystrokes into a file (a stored representation of
the document). In this case the input stream is from the keyboard and the output
is to a file.
When you print the file, you are converting that file (as an input stream) into a
printed representation---the output stream goes to the printer.
Whenever you type a Unix command, you are creating a process to carry out
the work of that command
Executing a process
To execute a process under Unix:
1. Your terminal should display the shell prompt. It looks like this:
yourname@yourcomputer<18>%
2. Type the name of the command. For example, there is a date command that
tells you the current date and time. Here is how your screen might look after
you use this command:
3.
4.
yourname@yourcomputer<19>% date
Sat Jan 28 14:20:38 MST 1995
yourname@yourcomputer<20>%
Many Unix commands allow command line arguments, that is, additional words or
phrases that follow the name of the command and give more information about what
to do.
For example, the man command will give you information about any Unix command.
To get information about the date command, for example, you can type:
yourname@yourcomputer<21>% man date
A command can have any number of arguments. For example, the cat command
concatenates any number of files. Suppose you want to display the contents of three
files named names, dates, and addresses on your display screen. This command would
do it:
Using pipelines
Suppose you want to take the output of some command, call it first, and use that
stream as the input of another command called second. This can be done via
redirection:
yourname@yourcomputer<28>% first >temp
yourname@yourcomputer<29>% second <temp
The output of the first command is redirected to a temporary file named temp, and
then the input of the second command is redirected from file temp.
We can do the same thing with a pipeline like this:
yourname@yourcomputer<30>% first | second
The pipe (|) symbol placed between two commands tells Unix to take the output
produced by the commands before the pipe symbol and make that the input of the
commands after the pipe symbol.