Linux operating system history command is fully controlled

  

$ history ... 62 rm 092210.sql 63 mysqldump 64 mysqldump -u root -p dev_gamenomad_com > 092210.sql 65 more 092210.sql 66 rm 092210.sql ... 9991 mkdir chapter05 9992 cd chapter05 9993 dir 9994 Npm install websocket-server 9995 node hello.js 9996 exit 9997 history

The sequence number associated with each command serves an important purpose, allowing the user to re-execute the relevant command by providing the sequence number directly followed by the exclamation point, as follows :

$ !10000 sudo /etc/init.d/apache2 start * Starting web server apache2

But this is not all. Linux history commands can do more, and will be mentioned later in this article.

Controlling Historical Extensions

Typing the up arrow key will display the previously executed command, and pressing the Enter key will execute the command again. But you can also use another option that may include faster history extensions:

$ !!

If you repeat the different permutations of the same two or three commands, you can Select to execute the command that appears at the occurrence of the previous command by identifying its negative displacement index. For example, to execute the previous command of the previous command (return two commands), use the following sequence:

$ !-2

Another way to execute an earlier command is to type the exclamation point followed by The beginning of the command serial number. The first command that matches the character object is executed. For example, suppose the last three commands are as follows:

$ history ... 9876 build-book /home/wjgilmore/easy_php 9877 mkdir chapter05 9878 cd chapter05 9879 touch chapter05.md

You can Execute the scripting script again by running the following command:

$ !b

Create a new directory and navigation with a two-step process to confirm it and shorten the history extension. In this case, I created a new directory called easy_bash at /home/wjgilmore/books. To confirm the directory, use !$ to get the last “character”:

$ mkdir /home/wjgilmore/books/easy_bash $ cd !$

Search Command History

Although you can flip through the command history (or use the grep command), you can also call a fragment of the command after you have searched it with Ctrl+R Open Select. The command line for the prompt will look like this:

(reverse-i-search)`':

Start typing a command fragment, and the command line will update in real time to reflect the most consistent one. After entering apa, a command similar to this will appear:

(reverse-i-search)`apa': sudo /etc/init.d/apache2 start

When you see want Command, hit Enter to execute it, or hit the up arrow to modify it before re-execution.

Adjusting Historical Behaviors

You can do a lot of interesting setting changes to control how command history behaves. For example, the default history size set by the Bash shell is 500 records, and this limit is quickly reached, even with small command line interactions. You can increase the limit by setting the HISTSIZE variable found in the Bash configuration file (.bashrc, located in the home directory).

HISTSIZE=10000

You will often encounter another history-related variable in the .bashrc named HISTCONTROL. This variable helps to specify what is stored in the history file (located in .bash_history, also in the home directory). For example, you might repeat the tail command while checking the latest log file attachments, just a few minutes after running tail. It is not practical to cluster historical files by repeating them, by setting it to ignoredups to make the HISTCONTROL variable ignore duplicate lines.

HISTCONTROL=ignoredups

Another HISTCONTROL setting for suspicious utility is to ignore spaces. The result of this HISTCONTROL setting is that all execution commands preceded by spaces are removed from the history file. This seems to be counterproductive for not tracking each command, but if you want to implement this function in addition to ignoredups, you can set both:

HISTCONTROL=ignoreboth

One feature to talk about is command replacement. Suppose you want to quickly configure a group of virtual hosts based on a virtual host profile template. These command sequences can be very long, as shown below:

$ cp vhost.template /etc/apache2/sites-available/dev.example.com $ cp vhost.template /etc/apache2/sites- Available/forum.example.com $ cp vhost.template /etc/apache2/sites-available/staging.example.com

Usually the way you execute this list of commands will be first typed and executed, then scrolled up Delete the trailing fragment (dev.example.com), then enter the next fragment (forum.example.com) and re-execute. Alternatively, you can use command substitution to quickly replace another related string with a one-line string as follows:

$ !!:s/dev/forum

The command line has brought a lot of benefits to the user in the point-and-click interface, allowing task execution and operating system navigation to be done quickly and elegantly. Maximizing the use of Linux history commands can only add these features and drive productivity to go even further.

The contents of the Linux history command are fully controlled. I hope that learning from the history of Linux commands can help you. Don't know if you learned it?

Copyright © Windows knowledge All Rights Reserved