History Introduction and Bash command Quick call

Source: Internet
Author: User

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.

    • 1. Execute nth command in the history of the command

# ! N

For example: above shows, 989 command is LS, when we use! 989, the system will execute the LS command again.

    • 2. Execute the previous command

# !!

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.

    • 3. Execute the last command in the command history that starts with a string (string)

#!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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.