Home  >  Article  >  Operation and Maintenance  >  What is the linux view history command?

What is the linux view history command?

藏色散人
藏色散人Original
2023-01-05 14:51:478043browse

The Linux view history command is "history". You can view the recently executed commands by executing the "history" command; you can add options after the "history" command, such as the "-c" option, which means to clear the history commands, " The -w" option means writing the historical commands in the cache to the historical command saving file "~/.bash_history".

What is the linux view history command?

#The operating environment of this tutorial: linux7.5 system, Dell G3 computer.

Linux view history command

View history command

You can execute the history command to view history command:

What is the linux view history command?

Go to the end to see:

These are the recently executed commands:

What is the linux view history command?

history command Options can be added later:

-c: Clear historical commands (including cache and files)

-w: Write historical commands in the cache to the historical command saving file ~/.bash_history (obviously Each user has his own file)

In fact, what we use history to view is the command in the cache:

For example, if I execute a command now:

What is the linux view history command?

Use history to view:

You can see the recently executed commands:

What is the linux view history command?

View files:

What is the linux view history command?

The last command that appears does not contain the previously executed command, because the historical command has not yet been written to the file at this time:

What is the linux view history command?

What is the linux view history command?

Only after normal login and exit, the system will write the commands in the cache to the file.

Historical commands can be saved up to 1000, which can be modified in /etc/profile:

What is the linux view history command?

This is the parameter:

What is the linux view history command?

If the maximum number is exceeded, the oldest record will be deleted.

After modification, execute source /etc/profile to make the environment variables take effect.

This command actually modifies the file /root/.bash_history:

What is the linux view history command?

##Invocation of historical commands

  • You can use the up and down arrows to call previous historical commands

  • Use "!n" to repeatedly execute the nth historical command

  • Use "!!" Repeat the last command

  • Use "! string" to repeat the last command starting with this string

Recommended study: "

Linux Video Tutorial"

The above is the detailed content of What is the linux view history command?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn