ls >> listing.txt
Command < File
Reads the le as input for the given command. For example, the read command
reads in the content of the le into the variable:
read a < foo
Command1 | Command2
Redirects the output of the left command as input for the right command. For
example, the cat command outputs the content of the /proc/cpuinfo le. This
output is used by grep to lter only those lines which contain cpu:
cat /proc/cpuinfo | grep cpu
Every channel has a le descriptor: 0 (zero) for standard input, 1 for standard output
and 2 for standard error. It is allowed to insert this le descriptor before a < or >
character. For example, the following line searches for a le starting with foo, but
suppresses its errors by redirecting it to /dev/null:
find / -name "foo*" 2>/dev/null
18.4 Using Aliases
An alias is a shortcut denition of one or more commands. The syntax for an alias
is:
alias
NAME
=
DEFINITION
For example, the following line denes an alias lt which outputs a long listing (option
-l), sorts it by modication time (-t) and prints it in reverse order while sorting (-r):
alias lt='ls -ltr'
To view all alias denitions, use alias. Remove your alias with unalias and the cor-
responding alias name.
18.5 Using Variables in Bash
A shell variable can be global or local. Global variables, or environment variables,
can be accessed in all shells. In contrast, local variables are visible in the current
shell only.
To view all environment variables, use the printenv command. If you need to know
the value of a variable, insert the name of your variable as an argument:
printenv PATH
A variable, be it global or local, can also be viewed with echo:
echo $PATH
232 Start-Up