CS155: Introduction to Unix

Spring 2018

More Redirection

See this page as a slide show

More Redirection

CS155 MoreRedirection

Streams

Streams and Redirection

Redirecting stderr and stdout

% ls
% rmdir alpha > output
rmdir: failed to remove 'alpha': No such file or directory

Example

% date >now
% ls -l
total 4
-rw------- 1 cs155 class 29 Aug 17 16:29 now
% ls -l now then
/bin/ls: cannot access then: No such file or directory
-rw------- 1 cs155 class 29 Aug 17 16:29 now
% ls -l now then >output
/bin/ls: cannot access then: No such file or directory
% ls -l now then >&output

Summary

command
Standard output and standard error both go to the terminal.
command > file
Standard output goes to file. Standard error goes to the terminal.
command >& file
Standard output and standard error both go to file.
command1 | command2
Standard output of command1 becomes the standard input of command2.
command1 |& command2
Standard output & error of command1 become the standard input of command2.

User: Guest

Check: HTML CSS
Edit History Source

Modified: 2018-01-06T14:39

Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2018 Colorado State University
CS Building