Linux Sysadmin Basics 04 -- Shell Features -- Pipes and Redirection

  • command1 | command2

    The output of one command is stored and then passed as the input for second command.

ps aux | less

  • three channels
    • STDIN —— 0
    • STDOUT —— 1
    • STDERR —— 2
  • output redirection
    • command > file : overwrite
    • command >> file : append
  • input redirection
    • command < file
  • error redirection
    • command 2> file
    • command 2>> file
echo "this should be in a file" 1> test.txt  # "1" can be ignored since it is the default
echo "this should be line 2" >> test.txt
mail -s "this is the subject" dave < message.txt
ls -alh thereisnosuchdir 2> err.txt

  • ps [options]

    report a snapshot of the current processes.

原文地址:https://www.cnblogs.com/goldenretriever/p/14332572.html