history 执行很简单:如下:参考
pi@raspberrypi:~ $ history
1 clear
2 ls
3 sudo apt update
4 df -h
5 sudo apt install vim
6 sudo reboot
7 clear
8 ls
9 sudo apt install vim
10 locale
Sometimes, however, we want to get more historical information, such as the time when a command was executed, to determine some actions.
针对 bash 这样设置
echo 'HISTTIMEFORMAT="%F %T "' >> ~/.bashrc
source ~/.bashrc
然后再次执行
history
1 2022-02-06 21:55:32 clear
2 2022-02-06 21:55:32 ls
3 2022-02-06 21:55:32 sudo apt update
4 2022-02-06 21:55:32 df -h
5 2022-02-06 21:55:32 sudo apt install vim
6 2022-02-06 21:55:32 sudo reboot
7 2022-02-06 21:55:32 clear
8 2022-02-06 21:55:32 ls
9 2022-02-06 21:55:32 sudo apt install vim
10 2022-02-06 21:55:32 locale
However, for terminals that use the ZSH environment (such as OHmyzsh), the above configuration does not take effect, and history-i is required
history -i
1 2020-07-05 16:48 mv ~/Downloads/aaaaa.zip ./
2 2020-07-05 16:48 unzip aaaaa.zip
3 2020-07-03 21:58 export http_proxy=http://127.0.0.1:1087;export https_proxy=http://127.0.0.1:1087;
4 2020-07-03 21:58 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
5 2020-07-03 22:10 sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
6 2020-07-03 22:13 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"\n
7 2020-07-03 22:44 cd OneDrive