linux-shell basics (2) Bash basic functions-historical commands and completion

1: history command history [options] [history command save file (that is, specify the location where the history command is saved, if it is not specified, it will be saved in the default directory, and the default location of each user is different)]

Options:

   -c: Clear history command (not used in special circumstances, it is easy to check)

   -w: Write the history command in the cache to the history command save file ~ / .bash_history (the default location under the root user)

Use the history command to see the commands we have entered before:

Understanding of -w If you use history directly, you can know the command you just entered, but it is not recorded in time in the default location.

In .bash_history

Finally, there is no ls and history

If you use history -w and then open this file: there is a record of the command you just entered.

The history command will save 1000 items by default, and can be modified in the environment variable configuration file / etc / profile. After the command is exceeded, the command at the head of the file will be deleted, and then a new command is added.

How to call history commands:

Use the up and down arrows to call the previous history command

Use "! N" to repeat the nth history command

Repeat the previous command using "!!"

Use "! String" to repeatedly execute the last command that starts with the string (to facilitate repeated use of longer commands)

2: Command and file completion

In Bash, command and file completion is a very convenient and commonly used function. As long as we re-enter a command or file, pressing the "Tab" key will automatically complete. If there is no completion statement, there are several commands that have entered characters at the beginning, press again, it will show what kinds of Zhengyang commands:

 

 

Published 158 original articles · Like 10 · Visitors 20,000+

Guess you like

Origin blog.csdn.net/ab1605014317/article/details/105455637
Recommended