GNU/Linux >> Linux の 問題 >  >> Linux

日付と時刻を含む Linux コマンド履歴

標準bashのシェル(およびその構成)に依存するのは、コマンドのみが日付と時刻なしで保存されるためです(.bash_historyを確認してください) そこにタイムスタンプがある場合)。

タイムスタンプを bash に保存するには、HISTTIMEFORMAT を設定する必要があります 以前 コマンドを実行します。 .bashrc で または .bash_profile .これにより、bash はタイムスタンプを .bash_history に保存します。 (# で始まるエントリを参照してください) ).


このリンクに関して、次のコマンドを実行することで、krzyk が提供する最初の解決策を永続的にすることができます:

echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
source ~/.bash_profile

これを試してください:

> HISTTIMEFORMAT="%d/%m/%y %T "

> history

もちろん、好みに合わせてフォーマットを調整できます。


zsh を使用している場合は、たとえば -E を使用できます または -i スイッチ:

history -E

man zshoptions を実行すると または man zshbuiltins これらのスイッチの詳細や、歴史に関連するその他の情報を見つけることができます:

Also when listing,
 -d     prints timestamps for each event
 -f     prints full time-date stamps in the US `MM/DD/YY hh:mm' format
 -E     prints full time-date stamps in the European `dd.mm.yyyy hh:mm' format
 -i     prints full time-date stamps in ISO8601 `yyyy-mm-dd hh:mm' format
 -t fmt prints time and date stamps in the given format; fmt is formatted with the strftime function with the zsh extensions  described  for  the  %D{string} prompt format in the section EXPANSION OF PROMPT SEQUENCES in zshmisc(1).  The resulting formatted string must be no more than 256 characters or will not be printed
 -D     prints elapsed times; may be combined with one of the options above

Linux
  1. Linux履歴コマンド

  2. 7 システムの日付時刻を表示および設定するLinux Dateコマンドの例

  3. Linux シェル スクリプトまたは変数の日付と時刻の書式設定

  1. timedatectlコマンドを使用してRHEL7Linuxシステムの日時を変更する

  2. Bash履歴で実行する各コマンドの日付と時刻を設定する

  3. CentOS / RHEL :history コマンド出力で実行されたコマンドの日時を取得する方法

  1. Linuxatコマンドでタスクをスケジュールする

  2. Linuxリアルタイムシナリオとそのソリューションの問題

  3. コマンド ラインの秘訣:Unix コマンドの実行日時を特定する方法