コマンドを使用してすべての端末出力をファイルに保存する方法はありますか?
- リダイレクトについて話すものではありません。
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
だけでセッションを開始でき、その後のすべてのコマンドとその出力は現在のディレクトリに名前が付けられたファイルに保存されます。次の方法で結果を別のファイルに保存することもできます。script
typescript
script
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
--command
man script
より多くのアイデアを得るために。