S5 version | Table of Contents (frame/ no frame) |
(19) Files |
Sidebar: standard I/O and redirection
Most commands send their output to "standard output". The shell provides a mechanism for redirecting this to a file, or to another program. The default is to the terminal. Many programs also read some input (default is the keyboard of the terminal). Again, there is a mechanism to tell any program to read its input from a file or another program instead.
> filename
- send output to the named file, creating it if needed. This is most common way new files are created
>! filename
- send output to the named file, creating it if needed, and forcing overwrite
>> filename
- append output to the named file, creating it if needed
< filename
- read input from the named file
prog1 | prog2
- run "prog1" and send its output to the input of "prog2". Both programs execute in "parallel". Actually they are usually timeshared, but appear to both run simutaneously
These facilities are available to all programs, but it is up to the individual programs whether they respect the conventions.
echo
" This is a test file" > test_file
ls
-a > ls_file
ls -FR /people2 | wc > how_many
touch
empty_file
more
[file_name]ls -FR | more
more /usr/man/cat1/cc.1
cat
/usr/man/cat1/cc.1
head
[file_name]
tail
[file_name]
.
cat
,
these utilities are not very useful with them. Two utilities, strings
and
od
are very useful for examining binary files outside of their specific
applications.
slide20.src last modified Jan 31, 2011 | Introduction | Table of Contents (frame/no frame) |
Printable (single file) |
© Dartmouth College |