すべての端末出力をファイルに保存

すべての端末出力をファイルに保存

コマンドを使用してすべての端末出力をファイルに保存する方法はありますか?

  • リダイレクトについて話すものではありません。command > file.txt
  • 履歴ではなく、完全なhistory > file.txt端末テキストが必要です。
  • ショートカットを使用しないでください。

それはまるでterminal_text > file.txt

ベストアンサー1

あなたはそれを使用することができますscript。デフォルトでは、scriptそのセッション中に端末に印刷されたすべての内容が保存されます。

~からman script:

script makes a typescript of everything printed on your terminal. 
It is useful for students who need a hardcopy record of an 
interactive session as proof of an assignment, as the typescript file 
can be printed out later with lpr(1).

端末に入力するscriptだけでセッションを開始でき、その後のすべてのコマンドとその出力は現在のディレクトリに名前が付けられたファイルに保存されます。次の方法で結果を別のファイルに保存することもできます。scripttypescriptscript

script output.txt

セッションからログアウトするにはscript(コンテンツの保存を中止)と入力しますexit

例は次のとおりです。

$ script output.txt
Script started, file is output.txt

$ ls
output.txt  testfile.txt  foo.txt

$ exit
exit
Script done, file is output.txt

これでファイルを読むと、次のようになります。

$ cat output.txt

Script started on Mon 20 Apr 2015 08:00:14 AM BDT
$ ls
output.txt  testfile.txt  foo.txt
$ exit
exit

Script done on Mon 20 Apr 2015 08:00:21 AM BDT

script-qプログラムメッセージを表示/保存せずに自動的に実行()するなどのオプションも多くあり、セッションの代わりに特定のコマンド()を実行することもでき、--quietその他さまざまなオプションがあります。確認する-c--commandman scriptより多くのアイデアを得るために。

おすすめ記事