In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "the specific use of the history command in Linux". In the daily operation, I believe that many people have doubts about the specific use of the history command in Linux. 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 the specific use of the history command in Linux! Next, please follow the editor to study!
Through the history commands under Linux, we can view the used commands, that is, historical commands. Today, this article will introduce in detail the specific usage of history under Linux. Let's learn about it.
What is history
In the bash function, it can remember the commands that have been used, and the biggest advantage of this function is that it can query the actions you have done!
As a result, you can know your running steps, so you can track the commands you have issued as a debugging tool!
II. Preservation of History
So where is the command record? In the .bash _ history in the home directory! However, it is important to note that ~ /. Bash_history records the commands that were run before the previous login, while the commands run this time are cached in memory. When you successfully log out of the system, the command memory will be recorded in .bash _ history!
Third, invoke the history command
Next, learn the use of the history history command.
The code is as follows:
History [n]
[root@jb51 Desktop] # history [- c]
[root@jb51 Desktop] # history [- raw] histfiles
Options and parameters:
N: number, which means to list the most recent n command line table!
-c: eliminate all history content in the current shell
-a: add the newly added history command to histfiles, if histfiles is not added
Then ~ / .bash_history is written by default.
-r: read the contents of histfiles into the history memory of the current shell
-w: write the current history memory to histfiles!
Example 1, which lists all history history records currently in memory
The code is as follows:
[root@jb51 Desktop] # history
# previous omission
1017 man bash
1018 ll
1019 history
1020 history
The information listed is divided into two columns, the first column is the code of the command in this shell, and the other is the content of the command itself! As for how many command records will be displayed, it has something to do with HISTSIZE!
Example 2, listing the three most recent pieces of data at present
The code is as follows:
[root@jb51 Desktop] # history 3
1019 history
1020 history
1021 history 3
Example 3, write the current data to histfile immediately
The code is as follows:
[root@jb51 Desktop] # history-w
# by default, the history record will be written to ~ / .bash_history!
[root@jb51 Desktop] # echo $HISTSIZE
one thousand
IV. Tricks for the use of history
1 、! The use of
⑴!! Repeat the previous command
two! The character repeats the previous command that begins with "character"
three! Num repeats the corresponding command according to the sequence number in the output of the history command
⑷!? Abc repeats the previous command containing abc
five! -n repeat the command before n commands
2. Key combination
⑴ uses the up and down keys to navigate up and down the previously executed command
⑵ type ctr+r to search for commands in the command history
The code is as follows:
[root@jb51 Desktop] #
(reverse-i-search) `':
(reverse-i-search) `hacks: cat / etc/shadow
Press enter to execute the command
⑶ wants to recall the parameters in the previous command
Esc +. Click the ESC key, and then click. Key)
Note:
History is saved in each user's own history and is located in the user's home directory.
After the user logs in, the execution command is stored in memory and can only be seen after logging in.
5. How to ensure history when login is launched each time
Under the desired user's home directory, edit ~ / .bash.logout and add a history-c save exit.
At this point, the study on "the specific use of the history command in Linux" 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.