输出重定向使用案例总结

假设两个文件 test.sh存在和test1.sh不存在

  • ls test.sh test1.sh 1>svc.txt
    正确输出重定向到文件svc.txt

  • ls test.sh test1.sh 1>svc.txt 2>err.txt
    正确输出重定向到文件svc.txt,把错误输出重定向到文件err.txt

  • ls test.sh test1.sh 2>&- 或者 ls test.sh test1.sh 2>/dev/null
    错误输出关闭掉,不输出错误信息

  • ls test.sh test1.sh 1>&- 2>&- 或者 ls test.sh test1.sh 1>/dev/null 2>/dev/null 或者 ls test.sh test1.sh &>/dev/null
    关闭正确输出错误输出

  • ls test.sh test1.sh >/dev/null 2>&1
    正确输出关闭,错误输出重定向到正确输出使用的设备上去

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章