Standard I/O and redirection
Standard I/O: most unix commands are setup to:
get input from standard input (If you are working from a bash prompt, standard input is normally the keyboard)
send output to standard output (If you are working from a bash prompt, standard output is normally the screen)
send error messages to standard error (If you are working from a bash prompt, standard error is also normally the screen)
Redirecting output. When you redirect standard output, the data that would normally appear on the screen is stored in a file instead. Redirect output to a file using > or >>
ls -l > flist
stores the output from ls in flist; if flist already exists, it is overwritten
ls -l >> flist
appends the output from ls to the file flist; if flist does not exist, it is created
Redirecting input. When you redirect standard input, any data that would normally be entered from the keyboard is obtained from a file instead. Redirect input from a file using <
mail floopy < jokes
sends floopy the contents of the file jokes instead of waiting for you to type a message on the keyboard
Redirecting standard error. Redirect standard error using 2>
find / -name jokes 2> /dev/null
(looks for a file named jokes; sends any "permission denied" messages to /dev/null)
Get a directory listing of /home and save the listing in a file called "one" in your own home directory. Use the cat command to make sure that "one" does contain the correct data.
Get a list of everyone currently logged on and save the list in a file called "users "in your own home directory.
Get a list of all of the processes that are running and add this list to the end of the "users" file.
Questions and Answers:
What command will suppress the display of the "permission denied" messages that are displayed when you use the find command?
find / -name penguin 2> /dev/null
What command will save a long directory listing of /etc in the file etc.filelist?
ls -l /etc > etc.filelist