Linux users who forget the history are destined to enter a lot of information ." This also makes powerful historical commands (including the historical variants of Bashshell) not only useful when invoking previous commands without re-entering them, but also useful when calling other rarely used commands, this saves the trouble of using them again. This command is based on the time "Linux users who forget the history are destined to enter a lot of information ."
This also makes powerful historical commands (including the Bash shell's historical variants) not only useful when invoking previous commands without re-entering them, but also when calling other rarely used commands, this saves the trouble of using them again. This command lists the previously executed commands in chronological order.
The output example of this command is as follows:
$ 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 numbers related to each command serve an important purpose. you can re-execute the commands by providing the sequence numbers that follow the exclamation point:
$! 10000
Sudo/etc/init. d/apache2 start
* Starting web server apache2
But this is not all. Linux History commands can do more, which will be mentioned later in this article.
Control history scaling
Click the up arrow to display the previously executed command, and press Enter to execute the command again. However, you can also use another option that may be faster, including the history extension feature:
$ !!
If you repeatedly execute different permutation and combinations of the same two or three commands, you can also choose to execute the command that appears at the previous command by recognizing its negative displacement index. For example, run the previous command (two commands are rolled back) with the following sequence:
$! -2
Another way to execute Early commands is to enter the serial number that begins with the exclamation point. 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 run the following command to execute the script again:
$! B
Use the two-step process to create a new directory for validation and navigate to shorten with historical extensions. In this example, I created a new directory named easy_bash in/home/wjgilmore/books. To confirm this directory, use it! $ To get the last "character" that is issued in the previous command ":
$ Mkdir/home/wjgilmore/books/easy_bash
$ Cd! $
Search command history
Although you can read the command history (or use the grep command), you can also call the snippet of the command after you use Ctrl + R to search for it. the prompt command line is as follows:
(Reverse-I-search )':
Start to input the command snippet, and the command line will update in real time to reflect the most consistent one. After you enter apa, a command similar to this will appear:
(Reverse-I-search) 'apa: sudo/etc/init. d/apache2 start
When you see the desired command, press Enter to execute it, or press the up arrow to modify it before re-execution.
Adjust historical behaviors
You can make a lot of interesting settings to control the behavior of commands in history. For example, the default history size set by Bash shell is 500 records, which is quickly reached, even if it is a small command line interaction. You can increase the limit by setting the HISTSIZE variable found on the Bash configuration file (. bashrc, in the main directory.
History size = 10000
In. bashrc named HISTCONTROL, you usually encounter another variable related to history. This variable helps specify the content stored in the history file (located in. bash_history, also visible in the main directory ). For example, you may have repeatedly executed the tail command when checking the latest log file attachment, just a few minutes before running tail. Repeat the previous Cluster file to make it impractical. you can set it to ignoredups to make the HISTCONTROL variable ignore the duplicate row.
HISTCONTROL = ignoredups
Another HISTCONTROL setting for suspicious utility is to ignore spaces. The result of this HISTCONTROL setting is that all the execution commands with spaces in front are deleted from the history file. This seems counterproductive for not tracking every command, but if you want to implement this function in addition to ignoredups, you can set the two:
HISTCONTROL = ignoreboth
One of the last features I want to talk about is the replacement of commands. Suppose you want to quickly configure a group of virtual hosts based on a virtual host configuration file template. These command sequences may 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
Generally, the method you run this command is to first input and execute the command, then scroll up and delete the ending segment (dev.example.com), then enter the next segment (forum.example.com), and re-execute it. In another method, you can use command replacement to quickly replace another string with one line, as shown below:
$ !! : S/dev/forum
This command line has brought a lot of benefits to the user in the point-to-click interface, allowing task execution and operating system navigation to be completed quickly and elegantly. To the greatest extent possible, history commands can only be used to add these features, promoting productivity will go further.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.