[Super introductory 3 minutes] Done! Display Linux OS command execution history
table of contents
Hello!
This is Inoue, a Persian cat from Beyond Shikoku Office.
it is a command that displays a list of the execution history of the
history " , which I, as an MSP, often use when dealing with problems on a daily basis. You can use it when you want to look back at the commands you executed.
history command
■Display a list of command execution history.
[root@test-aws-harukainoue ~]# history 5 ls -l 6 cd dir1 7 ls -l 8 touch haruka{1..10} ・ ・ ・ 995 netstat 996 netstat -l 997 netstat -t 998 netstat -p 999 netstat -nltp 1000 history
■Display the 5 most recently executed commands
[root@test-aws-harukainoue ~]# history 5 999 netstat -nltp 1000 history 1001 history 5 1002 history 1003 history 5
■Execute command by history number
[root@test-aws-harukainoue kadai2]# !855 df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 475M 0 475M 0% /dev tmpfs 492M 0 492M 0% /dev/shm tmpfs 492M 400K 492M 1% /run tmpfs 492M 0 492M 0% /sys/fs/cgroup /dev/xvda1 8.0G 2.8G 5.3G 35% / tmpfs 99M 0 99M 0% /run/user/1000
If you want to execute command number 855,
you can execute the command with the specified number ! " + " number (855)" without having to enter the command convenience!
■Show only command history including mkdir
[root@test-aws-harukainoue ~]# history | grep mkdir 194 mkdir haruka 197 mkdir dir3 291 mkdir test1 298 mkdir txt.1 txt.2 385 mkdir haruka 820 mkdir haruka 836 mkdir sntax 842 mkdir syntax 965 mk dir test 1003 history | grep mkdir
You can also narrow down and display only the execution history of the
mkdir using grep This can be done by typing | (pipe)" + " grep " + " command you want to narrow down after " history
Is there a way to search the execution history other than the history command? !
There was a feature where you could press
" Ctrl " + " r discovery! For example, search for command history that contains "w".
(reverse-i-search)`w': pwd
" Ctrl " + " r " to enter search mode, then enter the alphanumeric characters you want to search for.
“ Enter ” to execute the command.
How easy it is!
The history of the most recently used commands will be displayed, so you can go back one by one by pressing Ctrl " + " r
summary
If you use only
`` history ` `grep '', only the execution history that includes the target command will be displayed, which is likely to save time.
“ This looks like it will work! ” I end up using it frequently.
As someone like me who is always learning new things every day,
history " command is very useful because it allows me to look back and think, "Oh, what command did I use that time?"
I will continue to repeat trial and error and
write blogs about my favorite commands and commands that I personally want to understand better.
Growing every day, moving forward every day.
I have to update myself every day! ! !
Thank you for reading to the end.