Redhat Linux 9: Cách sử dụng history và chạy lại các lệnh đã chay trước đó
Link playlist
Red Hat Enterprise Linux Administration
https://www.youtube.com/playlist?list=PLIpLw6v7Z1qnIUiJipjgYEHwxF16TZbCN
2023 09 23 12 09 00
Previous commands
There is a way to recover the last commands run, which is referred to as history, in case you want
to re-run them. Just press the up arrow key (the one with an arrow pointing up) and the previous
commands will appear onscreen.
If there are too many commands in your history, you can search through them quickly by running
the history command:
[user@rhel-instance ~]$ history
1 su root
2 su
3 su –
4 id
5 id root
6 grep user /etc/passwd
7 echo $USER
8 echo $HOME
9 declare
10 echo $SHELL
11 echo EDITOR
Basic Commands and Simple Shell Scripts 74
12 echo $EDITOR
13 grep wheel /etc/gro
14 grep wheel /etc/group
15 cat /etc/group
16 grep nobody /etc/group /etc/passwd
You can run any of those commands again by using the ! command. Just run ! with the number of
the command and it will run again:
[user@rhel-instance ~]$ !5
id root
uid=0(root) gid=0(root) groups=0(root)
Tip
The !! command will run the very last command again, no matter which number.
Now, it is time to enjoy your superfast command line. Let’s learn more about the structure of directories
in Linux, to know where to go to find things, in the following section.