一般我们在Linux中执行过的命令会被记录到
/home/$USER/.bash_history
文件。要获取最近运行的命令,可以使用
Up
键盘键来检索以前的命令。使用Down
键盘键向相反方向找执行过的命令。历史文件可能包含很多条目,要从命令历史记录中重新执行特定命令,可以运行历史命令。
> history
1005 ls
1006 systemctl restart nginx
1007 systemctl status nginx
然后得到
number(s)
的command(s)
你想重新执行(例如,如果你想重新启动 nginx 并查看其状态)
> !数字编号
> !1006
systemctl restart nginx
> !1007
systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2021-10-27 20:54:35 CST; 13s ago
Process: 29074 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 29071 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 29069 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 29076 (nginx)
CGroup: /system.slice/nginx.service
├─29076 nginx: master process /usr/sbin/nginx
├─29077 nginx: worker process
└─29078 nginx: worker process
> !命令前缀
你还可以重新执行以前使用过的命令 (
systemctl status nginx
)!
后跟几个命令前缀字符(例如sys
或者system
)
> !sys
systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
...
//或者
> !system
systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
...
//或
> !systemctl
systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
...
注意:
!
和命令前缀之间不能有空白字符
相关文章