When you use the Linux command line a lot, using history efficiently can be a great productivity boost.

  1. When history is entered on the command line, it displays the sequence number and the command. For auditing purposes, it may be helpful to display the timestamp along with the command.

[root@localhost ~]# export HISTTIMEFORMAT=’%F %T ‘ [root@localhost ~]# history | less A few of the techniques that you can use on the Linux command line are history-related techniques

  1. When you have already executed a long command, you can simply search for history using the keyword and re-execute the same command without having to type it completely. Press Ctrl + R and type the keyword. In the example below, I search the wget, it contains wget in the history of the word shows the previous command “wget – O/etc/yum. Repos. D/CentOS – Base. ‘http://mirrors.aliyun.com/rep…” .

When the Ctrl + R key is pressed, the following status appears.

(reverse-i-search)`’:

Then type wget, and the command will filter out the matching history commands. If an unwanted command is displayed, you can continue to supplement the command line.

(reverse-i-search)`wget ‘: wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/rep… When you find the desired command line, you can press Enter to execute the command.

Filter out the matching history command, to change the parameters, you can press the TAB key, or the arrow key, you can exit the search mode to modify the history command, and execute.

3. Speed repeat the last command can be used!! Two exclamation points, execute the previous command. You can use it too! -1, execute the previous command. A few of the techniques that you can use on the Linux command line are history-related techniques

A few of the techniques that you can use on the Linux command line are history-related techniques

  1. Executing a specific command from HISTORY can use! Add a number and execute the history command specifying the line number.

[root@localhost ~]# ! 4 ss-tul Netid State recv-q send-q Local Address:Port Peer Address:Port Process udp UNCONN 0 0 127.0.0.1:323 0.0.0.0:* 4 ss-tul Netid State recv-q send-q Local Address:Port Peer Address:Port Process udp UNCONN 0 0 127.0.0.1:323 0.0.0.0:* UDP UNCONN 0 0 [::1]:323 [::]:* TCP LISTEN 0 128 0.0.0.0: SSH 0.0.0.0:* TCP LISTEN 0 128 [::]: SSH [::]:* A few of the techniques that you can use on the Linux command line are history-related techniques

  1. By default, in Centos8, history stores 1000 historical records. You can use the following command to view:

[root@localhost ~]# echo $HISTSIZE 1000 Add the following two lines to.bash_profile and execute source ~/.bash_profile to take effect. In the following command, make HISTORY store fewer history records, only 200.

[root@localhost ~]# echo “HISTSIZE=200” >> .bash_profile [root@localhost ~]# echo “HISFILETSIZE=200” >> .bash_profile [root@localhost ~]# source ~/.bash_profile HistSize controls the amount of history displayed.

The HISTFILESIZE variable controls the number of history entries in the.bash_history file.

  1. By default, the history file is called.bash_history, and you can change its file name using the HISTFILE variable. You can write the HISTFILE variable to ~/.bash_profile, as shown in the following example:

[root@localhost ~]# echo “HISTFILE=/root/.cmd_hist” >> ~/.bash_profile [public ~]# reboot You can see that the new history file is ready to store the history. A few of the techniques that you can use on the Linux command line are history-related techniques

  1. Clear history Use the -c option to clear history:

[root@localhost ~]# History-C – A few tips on the Linux command line that use history

  1. If you want to disable history altogether, set histSize and histFileSize to 0, as shown below.

[root@localhost ~]# echo “HISTSIZE=0” >> .bash_profile [root@localhost ~]# echo “HISFILETSIZE=0” >> .bash_profile [root@localhost ~]# source ~/.bash_profile A few history-related tricks on the Linux command line are used

To summarize, when you use the Linux command line frequently, using history effectively can greatly increase productivity.