Shell Introduction and command history

Source: Internet
Author: User

1. What is a shell?

Open the system, enter ZS, press the Tab key, the command Zsoelim appears,

Description No zsh command, this time can be installed, first enter the command yum list |grep zsh, enter, search,

You can see that there are zsh commands, there are ksh commands, this way we will not install.

2. Command history

The commands that we have executed are actually saved to a file. You can view the previous commands by pressing the UP ARROW key, so where are these commands saved? There is a file in the user's add directory, the root user see,

Can cat view, command very much, intercept part, see,

To know how many commands have been executed before, you can use the history command to view, enter history, return, intercept part of the picture, see,

Can see before the history is 672, then this file. Bash_history can store up to 1000 commands. This can be queried by the environment variable histsize, see,

There is also a command history-c that can be emptied of the current historical command, see,

So can the command empty the configuration file? Enter the command cat. Bash_history, enter, see,

The contents of the configuration file can be seen, not emptied, stating that the history-c command simply empties the history of the command in memory, using the UP ARROW keys, and not the previous history commands, just a few commands.

So, when are we going to save the order to this file? To give an example,

Now execute the LS command three times and then enter the command cat. Bash_history, enter,

Can see that the last few lines of these commands, and no LS, again using history to view, see,

At this point, you can see the LS command, stating that the command just executed, currently exists only in memory, only after exiting the terminal, these commands can be saved to the configuration file. Bash_history.

environment variable histsize where to define it? In/etc/profile, use the Vi/etc/profile command to enter, search for hist,

The default amount of Histsize is 1000.

If you feel too little, you can change it to 5000. Enter edit by letter I, after completion, press ESC to exit edit, enter: Wq, exit after saving.

After changing the value, will not immediately become 5000, need to execute the source command, to take effect, see,

Now look at the history command,

, only the ID number and the specific command are shown, can you record the run time of the corresponding command, which requires re-assignment to the histsize, see,

Here we need to note that the assignment of this change, only valid for the current terminal operation, will be invalidated once the terminal is opened again. That is, the system default environment variable does not exist, do not define. This is the time to execute the history command,

You will see that the format of the command history has changed, and the date and time when the command was run is recorded. These changes are the result of environmental variables. For the change to take effect, you can edit the/etc/profile file, enter the command vim/etc/profile, return, see,

Search HIST, see,

Add a line of red box content, save and exit, execute command source,

Exit Putty, re-login, execute the history command, see,

As you can see, the date and time are permanently in effect.

Then do the experiment, see,

After executing this command, the file can only be appended and cannot be deleted.
When the terminal does not exit normally, it will not save the command that was executed or save the command.

Another talk about,!! ,!n (n for numbers),!word (Word denotes command word), see,

Shell Introduction and command history

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.