In daily work, the ability to use commands quickly and accurately is essential, so let's introduce some of the tips below.
First, find the command history--history
Use history to quickly find the commands you've entered before.
# History
As you can see, the commands you have entered appear in the list. What's the use of the command number in front? See below for a detailed explanation.
Additional options:
# History N shows the most recent n commands, such as historical 5 # history-d n Delete the nth command, this n is the preceding number, for example history-d 990 # history-c emptying the command histories # hist Ory-a writes the history of the command in the current session to the specified file
What is the specified file? is the environment variable information for the historical record, which is usually saved in the user's home directory. Bash_history.
# echo $HISTFILE Use this command to view environment variables
# echo $HISTFILESIZE View maximum number of saves
Second, quick call Bash command
When we finish a command, the system will record it for viewing or quick call. So how do you make the Bash command fast to use? Please look below.
# ! N
For example: above shows, 989 command is LS, when we use! 989, the system will execute the LS command again.
# !!
For example: I execute the uptime command, then immediately use!!, the system will tell you what the previous command used, and perform the retrieval results.
#!string
For example: I create a new folder in the home directory mkdir test, and then delete the RM-RF test.
Now look, there is no test directory under the home directory. I execute the!MK, you can see, the command that created the directory was executed again, and then with!RM, the directory was deleted. But note that although this is very convenient, but because some commands are very similar at the beginning, so it is easy to create a false operation, the safe way to look at the history of it!
#!MK
#!RM
4. Call the last parameter of the previous command ——! $
I first ls/var/log/the directory, when/var/log/is the parameter of the LS command.
Below I would like to see the messages file in this directory, you can write this (to prevent the brush screen, use less).
As you can see, the command will automatically replace!$ for/var/log/, is not very convenient! Similarly, press ESC, release and press. You can also call the parameters of the previous command, please try it yourself.
If the above description has any wrong or wrong place, please also identify for me, thank you for watching, thank you! qq:82800452
History Introduction and Bash command Quick call