Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Linux history command

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use the Linux history command". In daily operation, I believe many people have doubts about how to use the Linux history command. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use the Linux history command". Next, please follow the editor to study!

History displays or manipulates a list of history.

Summary history [- c] [- d offset] [n] history-anrw [filename] history-ps arg [arg...] The main purpose is to display a list of history.

List of operation history.

Option-c clears the history list. -d offset deletes records based on offset. A positive number represents a record of the offset position, and a negative number represents a record of the offset position from the end forward. -an adds the history line of the current terminal to the history file. -n appends history lines that have not been read from the history file to the current history list. -r reads the history file and appends its contents to the history list. -w appends the current history list to the history file and appends them to the history list. -p performs a history extension on each arg and displays the results on standard output without storing the results in the history list. -s appends each arg to the history list as a single entry. Parameter n: optional, only the most recent n records are listed.

Filename: optional, representing the history file; the default calling order is filename, environment variable HISTFILE, ~ / .bash_history.

The return value returns success unless an illegal option is provided or an error occurs.

The example uses the history command to display the last 10 historical commands

[root@localhost] # history 1092 ls 93 cd. 94 ls 95 exit 96 ls-a 97 cd .ssh / 98 ls 99 cat known_hosts 100 exit 101 history 10 emptying History

[root@localhost ~] # history-c more instances:

# execute the n historical command [root@localhost ~] #! n # execute the last command at the beginning of xxx [root@localhost ~] #! xxx note that symbols can be used on the command line! Executes the history command of the specified sequence number. For example, to execute the second history command, enter! 2.

When the terminal is closed, the history list will be written to the history file ~ / .bash_history.

The environment variable HISTSIZE determines the number of commands stored in the history file, with 1000 commands stored by default.

If the environment variable HISTTIMEFORMAT is a non-null value, its value is added before each displayed history record as a format string for strftime (3) printing the associated timest otherwise, the timestamp is not printed.

This command is a bash built-in command. For help, please see the help command.

At this point, the study of "how to use the Linux history command" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report