2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WSLのコマンド履歴を自動で保存する

Posted at

WSLでコマンド履歴をログファイルに自動で残したい。

設定

~/.profile に以下追記

script -f <ディレクトリ>/$(date +%Y%m%d%H%M%S)_wsl.log

例:

script -f /home/emi/wslscript/$(date +%Y%m%d%H%M%S)_wsl.log

↓再起動

Script started, file is /home/emi/wslscript/20220331220459_wsl.log
emi@LAPTOP-AOJR4Q2P:~$

これでログ保存開始できた。

ログの確認

  • cat ファイル名.log
  • less -r ファイル名.log

で綺麗に参照できる。

例:

emi@LAPTOP-xxxxx:~/wslscript$ less -r 20220331220459_wsl.log
"20220331220459_wsl.log" may be a binary file.  See it anyway? ⇒y

q で抜ける。

Windowsのエクスプローラーから直接開くとやや見づらい。
image.png

参考

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?