.bash_historyファイルに、コマンドが入力されたディレクトリ、日付、およびコマンドをリストする方法はありますか?
承認された回答:
ディレクトリを表示する履歴コマンド:NO! 🙁
日付を表示する履歴コマンド:YES! 🙂
それは(man history
から) ):
The history list is an array of history entries. A history entry is declared as follows: typedef void * histdata_t; typedef struct _hist_entry { char *line; char *timestamp; histdata_t data; } HIST_ENTRY;
したがって、コマンドが入力されたディレクトリについては何もありません。
特定のコマンドが実行された正確な時刻を知るには、help history
を参照してください。 :
If the $HISTTIMEFORMAT variable is set and not null, its value is used as a format string for strftime(3) to print the time stamp associated with each displayed history entry. No time stamps are printed otherwise.
したがって、必要なのは$HISTTIMEFORMAT
を設定することだけです。 現在のシェルでは次のようなものです:
export HISTTIMEFORMAT="%F %T "
永続的に設定するには、次のコマンドを実行します。
echo 'export HISTTIMEFORMAT="%F %T "' >> ~/.bashrc
上記のコマンドは、新しい行を追加します(export HISTTIMEFORMAT="%F %T "
)~/.bashrc
の最後に ファイル。
ここで、history
の出力 次のようになります:
...
1613 2013-11-13 13:00:15 cat .bash_history
1614 2013-11-13 13:01:04 man history
1615 2013-11-13 13:11:58 help history
1616 2013-11-13 13:19:07 ls
1617 2013-11-13 13:19:09 cd
1618 2013-11-13 13:19:15 history