History introduction and quick calling of bash commands
In daily work, quick and accurate use of Linux commands is essential. Here are some tips.
1. Search for command history-history
Use history to quickly find the commands you have previously entered.
# History
As you can see, the commands you have entered are displayed in the list. The command number is in front. What is the purpose? Please refer to the details below.
Additional options:
# History N displays the last N commands, such as history 5
# History-d N Delete the nth command. This N is the previous number, for example, history-d 990.
# History-c clear command history
# History-a writes the command history in the current session to the specified file
What is the specified file? It is the historical environment variable information, which is usually stored in the user's home directory. bash_history.
# Echo $ HISTFILE Use this command to view environment variables
# Echo $ HISTFILESIZE
Use the record tool (history, screen, script) in Linux
Linux history command details [graphic]
Linux history commands
Ii. Quick invocation of bash commands
After a command is typed, the system records it for viewing or calling quickly. So how can we quickly use bash commands? See the following.
1. Execute the nth command in the command history
#! N
For example, the above shows that the 989 command is ls. When we use it! 989, the system will execute the ls command again.
2. Execute the previous command
#!!
For example, I will execute the uptime command and then use it immediately !!, The system will tell you what the previous command was using and execute the command to retrieve the result.
Bash built-in commands
3. Execute the last command starting with a string in the command history
#! String
For example, create a folder named mkdir test in the home directory, and delete the rm-rf test folder.
Now, there is no test directory in the home directory. I executed it! Mk. You can see that the command for creating a directory was executed again and used again! Rm. The directory is deleted again. But note that this is very convenient, but some commands start with very similar, so it is easy to cause misoperations, the security method should look at history!
#! Mk
#! Rm
4. Call the last parameter of the previous command --! $
First, I will use the ls/var/log/directory. At this time,/var/log/is the parameter of the ls command.
Below I want to view the messages file under this directory, you can write it like this (to prevent screen flushing, use less ).
As you can see, the command will be replaced automatically! $ Is/var/log/. Is it very convenient! Similarly, if you press ESC and press. Again, you can call the parameters of the previous command.
If there is anything wrong or wrong with the above description, please identify it for me. Thank you for watching it. Thank you!
This article permanently updates the link address: