[Linux study notes] Chapter 8 Linux shell basics

8.1 Shell Introduction The
shell is a command interpreter that provides human-computer interaction.
Support specific syntax.
Each user can have their own specific shell (bash).
CentOS7 defaults to bash (Bourne Agin Shell).
Others include zsh, ksh, etc.


8.2 Command History
Command history is stored in the ~/.bash_history file.
history View the previously used commands. The last 1000 records are saved by default. The number of records is set by the variable HISTSIZE. HISTSIZE can be configured in the configuration file /etc/profile. After the configuration, the source is required to take effect.
history -c clears the command history in the current memory, but cannot clear the commands in ~/.bash_history.
The current command is stored in memory, and will be saved to the .bash_history file when you exit the terminal.
HISTTIMEFORMAT=”%Y/%m/%d %H:%M:%S” sets the display time format, which can be configured in /etc/profile to take effect permanently. Once configured, history will show when the command was executed.
chattr +a ~/.bashhistory plus a permission, can only be appended, not deleted, so that the command history is permanently saved.
If the terminal is not exited normally, there will be an error in saving the command history.
!! Execute the previous command.
!n n is a number, execute the nth command in the command history.
!word executes the most recent command starting with word.


8.3 Command Completion and Alias
​​Tab , tap once (only auto-completion), tap twice (multiple lists).
CentOS7 supports auto-completion of command parameters. Relevant packages need to be installed: yum install -y bash-completion , and then reboot the system to take effect.
Command alias alias command='comand blablabla'
alias to view command aliases in the system.
Command aliases can be configured in files in the ~/.bashrc and /etc/profile.d/ directories.
unalias command cancels the custom command alias.


8.4 Wildcards

  • Matches any number of any characters.
    ? Matches an arbitrary character.
    [0-3] or [0123] matches any character in square brackets. [0-9a-zA-Z]
    {1,2,3,a} matches any of the curly braces.

8.5 Input and output redirection
\> output redirection.
command > FILE writes the correct output of command to FILE.
command >> FILE appends the correct output of command to FILE.
command 2>FILE Writes the error message output by command running to FILE.
command 2>>FILE appends the error message output by command running to FILE.
True + False: >+2> is represented by &>.
command &>FILE writes the correct and incorrect information output by command running to FILE, and also supports appending command &>>FILE .
command >FILE1 2>FILE2 can save correct and incorrect information separately, which is mostly used in writing shell scripts. For example:
ls 1.txt 2.txt >t.txt 2>e.txt
< input redirection (almost never used).
command <FILE Enter the contents of the FILE file into the command command. Such as:
wc -l <1.txt to view the number of lines in the content of 1.txt.
wc -l >1.txt is to write the correct output obtained by wc -l to 1.txt.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324770980&siteId=291194637