Linux

與輸出 shell 一起執行的重定向命令

  • December 20, 2013

我想將執行的命令與輸出一起重定向到一個文件。

例如:#ls >ls_out.txt

ls_out.txt 應該是這樣的:


ls

文件 1 文件 2


謝謝!

你可以使用“腳本”命令:像這樣的東西:

localhost:test_sf user1$ ls
file1   file2   file3
localhost:test_sf user1$ script ls_out.txt  #starting script command ls_out.txt will contain output
Script started, output file is ls_out.txt
bash-3.2$ ls 
file1       file2       file3       ls_out.txt
bash-3.2$ exit
exit

Script done, output file is ls_out.txt
===================================================================================
localhost:test_sf user1$ cat ls_out.txt  #verify the contents now.
Script started on Wed Dec 18 12:05:23 2013
bash-3.2$ ls 
file1       file2       file3       ls_out.txt
bash-3.2$ exit
exit

您只需要擺脫“bash-3.2$ exit exit”部分。

引用自:https://serverfault.com/questions/562225