Linux System Shell Basics (i) (in edit)

Source: Internet
Author: User

Shell is an important application in the operating system, especially for Linux, the command-line mode of the operating system, the shell is of great significance.

First, what is the shell

The shell is a command interpreter that provides interaction between the user and the machine. Every time we log in to the system, the interface that appears is the shell, which is equivalent to the command we entered in the interface, and the shell transforms what we have entered into something that the system can understand to execute. The shell supports a specific syntax, a bit like the C language, which supports logical judgments, if while statements.

This is the basic shell.
Centos7 The default shell is bash, and other types of shells, such as zsh, Ksh, are also supported in the system.

Ii. Introduction to historical variables (histsize) and its parameters

The commands currently entered by the user in the CENTOS7 system are stored in the user's home directory, for example, the root user command exists in the/root/.bash_history file.

The number of commands that this file can store is determined by the histsize variable. The initial value of this variable is 1000.

Each time you exit the terminal, the command you have knocked on will be saved in the/root/.bash_history file.
The histsize variable value is set in/etc/profile, which can change many system parameters, including the number of commands, the format of the command, and so on.

1. Modify the number of commands recorded by the system
Operate in the/etc/profile file, open with VI or VIM, navigate to 46 lines (by the way, review the VIM command, 46J)

Change the value in the box to the value you want, say 5000

Save exit, use the source command to overload the system under the profile to make the changes effective

Look at the results, get it done!

2, modify the record content, record the time of each command execution
In two cases, one is only valid for the current terminal and fails after disconnection.
Command:HISTTIMEFORMAT="%Y%m%d %H:%M:%S"

Permanently adding this content to/root/.bash_history requires changing the/etc/profile file, as follows:
As in the previous example, in the/etc/profile file operation, with VI or VIM open, positioning to 46 lines (by the way, review the VIM command, 46J)

Add "histtimeformat="%y%m%d%h:%m:%s "content under Histsize line

Save exit, use the source command to overload the system under the profile to make the changes effective

Disconnect and re-login the system, see the results, done!

3, the history of the permanent preservation of the command
Just add +a permissions to the/root/.bash_history file in the current user's home directory, and even if you set the size of the histsize, he will still record all the commands you have entered.
Command: chattr +a ~/.bash_history

4. Execute the last command in the history record
Command:!! (two exclamation marks)

5, the operation of the article XX command
Command:! X (number)

6. A recent history command that starts with a key word
For example, I'm going to execute a command that starts with the last init, type! Init He will execute the last one in the history record. You can see that it is init 0.

Linux System Shell Basics (i) (in edit)

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.