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

Learn the history of Linux commands

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article will explain in detail about learning the history of Linux commands. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Preface

Have you ever executed a long command when using linux development, and then re-typed it after a while to execute it?

You all know that in linux, you can find a previously executed command by using the ↑ up arrow, but this command is hard to find if it takes a long time to execute.

If you are using a xsheel client, you can't find it when the client is closed.

So how to solve this problem?

1. Linux operation on command history 1. Use history to view the history

When you execute the history command, the 1000 commands you executed before will be displayed.

But if you don't log out or shut down, you can save more than 1000 commands, and this 1000 is a default.

Of course, this value can also be modified, if you want to change, you can execute the following command.

Echo "HISTSIZE=2000" > > .bash _ profile echo "HISFILETSIZE=2000" > > .bash _ profilesource ~ / .bash_profile (just make it effective)

If you are in charge of the server, you need to see what command was executed at what point in time, you only need to execute the following command

Export HISTTIMEFORMAT= "F T"

Then the time you can see when you execute the history command

2. Search the execution record directly using Ctrl + r

For example, a command usr/local/nginx/sbin/nginx-t is executed to check whether the nginx configuration is correct.

If you want to find a command, just press Ctrl+r and type usr.

3. Repeat the previous command

There are several ways to execute the previous command, one of which is estimated to be ↑.

But what I said to Daji today is that it can be used! To operate

Of course, you can also use!-1 to execute

4. Execute the command corresponding to the serial number

Where this sequence number comes from is the first command history mentioned in this article. After execution, the sequence number of each command appears.

In the following picture, I want to execute the 1020th order, so it can be executed like this! 1020.

In fact, this command has some programming foundation should be able to figure it out, in the third section we used! To execute the last order, which is actually the last record in history.

By the same token, this command uses! 1020, so that the memory of the command is regular.

5. Modify the total number of historical rows

In the first section, I also briefly talked about the modification of the total number of lines, but did not do it myself, so let's do it next.

In this command, HISTSIZE controls the number of history commands displayed.

HISTFILETSIZE controls the amount of storage in the file.

1039 2021-03-02 22:29:37 echo "HISTSIZE=2000" > > .bash _ profile 1040 2021-03-02 22:29:58 echo "HISTFILETSIZE=2000" > > .bash _ profile 1041 2021-03-02 22:30:20 source ~ / .bash_profile

Since this command can change the number of history displays, it can also change the number of file storage history.

Imagine what to do if you don't want the server to record history!

Is it OK to change both values to 0?

Can you give it a try by yourself?

6. Clear the history

Clear the history and execute the command history-c

This is the end of this article on "Learning the history of Linux commands". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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

Servers

Wechat

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

12
Report