Output redirection in pipes

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to: navigation, search
← Input redirection in pipesHomeWhy use pipes →

You redirect the standard output of the last command using a pipe with > or >> redirection symbol. The syntax is:

command1 | command2 > output.txt
command1 | command2 arg1 > output.txt
command1 < input.txt | command2 > output.txt
command1 < input.txt | command2 arg1 arg2 | command3 arg1 > output.txt

For example, sort all process memory wise and save the output to a file called memory.txt:

ps -e -orss=,args= | sort -b -k1,1n > memory.txt

Or directly send an email to your account, enter:

ps -e -orss=,args= | sort -b -k1,1n | mail -s 'Memory process' [email protected]
← Input redirection in pipesHomeWhy use pipes →