Linux centos7 Shell Introduction, Command history, command completion and aliases, wildcard characters, input and output redirection

Source: Internet
Author: User
Tags aliases aliyun egrep

First, Shell introduction

Shell scripting is an essential part of everyday Linux system management, not a shell, not a qualified administrator.

The shell is the intermediate medium that the system interacts with the computer hardware, a system tool. There is actually a layer between the shell and the computer hardware-the system kernel. If the computer compared to human body, the system kernel is the human brain, as for the shell, it is more appropriate than the facial features.

In fact, the user is not directly facing the computer hardware but the shell, the user tells the shell, and then the shell to the system kernel, and then the kernel to control the computer hardware to perform various operations.

The shell version of the CentOS installation is bash (Bourne Again shell), an enhanced version of SH (Bourne shell). Bourne Shell is the first popular version, the founder is Steven Bourne, in honor of his name as Bourne shell for short sh

Ii. History of the Order

The commands we execute are recorded, and the Presets record 1000 historical commands, which are saved in the. bash_history file in the user's home directory.

Commands that run in the current shell are saved until the user exits the current shell normally. Bash_history

! is a special character related to the command history

!! : consecutive means of executing the previous instruction

!n: Here n is a number that represents the nth instruction in the history of the execution of the command

! string (string greater than or equal to 1):!PW indicates execution history the most recent command that begins with PW

[Email protected] ~]# ls/root/.bash_history
/root/.bash_history
[Email protected] ~]#
[[email protected] ~]# cat!$ can save 1000
Cat/root/.bash_history
Ping wwwbaiducom
Vi/etc/sysconfig/network-scripts/ifcfg-ens33
Systemctl Restart Network.service
Ifconfig
Route-n
Ping www.baidu.com
If config
Ifconfig
Ping wwww.baudu.com
Systemctl RESTSRT Network.service
Systemctl Restart Network.service
Journactl-xe
Systemctl Status Network.service
Etc/profile
Systemctl Restart Network.service
SSH 192.168.1.106

....

[[email protected] ~]# echo $HISTSIZE See how much you can save
1000
[[Email protected] ~] #history-C clears the history command, but does not delete the command, you can still use the command

[[Email protected] ~]# history view used commands

[[email protected] ~]# vi/etc/profile View text

Hostname= '/usr/bin/hostname 2>/dev/null '
histsize=1000 Maximum storage capacity

Change to 500 bar

histsize=5000

[Email protected] ~]# echo $HISTSIZE
1000
[[email protected] ~]# source/etc/profile refresh a bit
[Email protected] ~]# echo $HISTSIZE
5000
[Email protected] ~]#

[[email protected] ~]# histtimeformat= "%y/%m/%d%h:%m:%s" specify format

[Email protected] ~]# echo $HISTTIMEFORMAT
%y/%m/%d%h:%m:%s

[Email protected] ~]# vi/etc/profile

Hostname= '/usr/bin/hostname 2>/dev/null '
histsize=5000
histtimeformat= "%y/%m/%d%h:%m:%s " Paste variable

[Email protected] ~]#

[Email protected] ~]# Vi/etc/profile
[Email protected] ~]# Source/etc/profile
[Email protected] ~]# echo $HISTTIMEFORMAT
%y/%m/%d%h:%m:%s
[Email protected] ~]#

Chattr +a ~/.bash_history Permanent Save

[Email protected] ~]# chattr +a ~/.bash_history

[[Email protected] ~]# init 0 normal shutdown to save

[Email protected] ~]# pwd

/root
[[email protected] ~]# !! Executes the previous command
Pwd
/root

[[email protected] ~]# !555 execute No. 555 order
Fdisk-l

[[email protected] ~]# !PW to perform the most recent command that begins with PW
Pwd
/root
[Email protected] ~]#

Iii. command Completion and aliases

1. Command completion: Tab, knock, can help us to complete a command, a path or a file name, two, the system will be all the commands or files are listed

Parameter completion, installation Bash-completion

[email protected] ~]# Yum install-y bash-completion
Loaded plugins: Fastestmirror
Base | 3.6 KB 00:00:00
Extras | 3.4 KB 00:00:00
Updates | 3.4 KB 00:00:00
Loading mirror speeds from cached hostfile
* base:mirrors.cn99.com
* extras:mirrors.aliyun.com
* updates:mirrors.aliyun.com
Resolving dependencies
--Checking transactions
---> Package bash-completion.noarch.1.2.1-6.el7 will be installed
--Resolve dependency completion

Dependency resolution

=============================================================================================================== ==========================
Package schema version Source size
=============================================================================================================== ==========================
Installing:
Bash-completion Noarch 1:2.1-6.el7 Base-K

Transaction summary
=============================================================================================================== ==========================
Installing the 1 package

Total Downloads: $ k
Installation Size: 259 K
Downloading packages:
bash-completion-2.1-6.el7.noarch.rpm | KB 00:00:00
Running transaction Check
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: 1:bash-completion-2.1-6.el7.noarch 1/1
Verified in: 1:bash-completion-2.1-6.el7.noarch 1/1

has been installed:
Bash-completion.noarch 1:2.1-6.EL7

Complete!
[email protected] ~]# reboot

[[Email protected] ~]# system
Systemctl Systemd-coredumpctl systemd-inhibit Systemd-run
Systemd-analyze Systemd-delta Systemd-loginctl Systemd-stdio-bridge
Systemd-ask-password Systemd-detect-virt Systemd-machine-id-setup Systemd-sysv-convert
Systemd-cat Systemd-escape systemd-notify Systemd-tmpfiles
Systemd-cgls systemd-firstboot Systemd-nspawn systemd-tty-ask-password-agent
Systemd-cgtop systemd-hwdb Systemd-path
[Email protected] ~]# Systemctl Res
Rescue reset-failed Restart

2. Aliases

Alias names the command again

User's own configuration alias file ~/.BASHRC

or in ls/etc/profile.d/.

To cancel a custom alias

Unalias

Custom alias put to ~/.BASHRC

[Email protected] ~]# systemctl restart Network.service
[[email protected] ~]# alias restartsev= ' systemctl restart Network.service '
[Email protected] ~]# Restartsev
[[email protected] ~]# alias
Alias cp= ' Cp-i '
Alias egrep= ' Egrep--color=auto '
Alias fgrep= ' Fgrep--color=auto '
Alias grep= ' grep--color=auto '
Alias l.= ' ls-d. *--color=auto '
Alias ll= ' Ls-l--color=auto '
Alias ls= ' ls--color=auto '
Alias mv= ' Mv-i '
Alias restartsev= ' systemctl restart Network.service '
Alias rm= ' Rm-i '
Alias Which= ' Alias | /usr/bin/which--tty-only--read-alias--show-dot--show-tilde '
[Email protected] ~]#

User's own configuration alias file ~/.BASHRC

[Email protected] ~]# Vi. BASHRC

#. BASHRC

# User specific aliases and functions

Alias rm= ' Rm-i '
Alias cp= ' Cp-i '
Alias mv= ' Mv-i '

# Source Global Definitions
if [-F/ETC/BASHRC]; Then
. /etc/bashrc
Fi
~

[[email protected] ~]# unalias Restartsev de-alias
[Email protected] ~]#
[Email protected] ~]# Restartsev
-bash:restartsev: Command not found
[Email protected] ~]#

Four, wildcard, input and output redirection

LS *.txt

Ls?. Txt

LS [0-9].txt

ls {1,2}.txt

Cat 1.txt > 2.txt specify 1.txt input to 2.txt

Cat 1.txt >> 2.txt append 1.txt to 2.txt

LS Aaa.txt 2 >err

LS Aaa.txt 2 >>err

WC-| < 1.txt

command >1.txt 2>&1

[[email protected] ~]# ls *.txt

[[email protected] ~]# LS *
0.txt.gz 4913 5036 anaconda-ks.cfg.01 anaconda-ks.cfg.1 davery davery~ user1

1. txt:

Make

UEAR1:
[Email protected] ~]#

[[email protected] ~]# Touch 1.txt
[[email protected] ~]# Touch 2.txt
[[email protected] ~]# Touch 3.txt
[email protected] ~]# ls?. Txt
2.txt 3.txt

1. txt:
[Email protected] ~]#

[[email protected] ~]# ls [0-3].txt
2.txt 3.txt

1. txt:
[[email protected] ~]# ls [1].txt
[[email protected] ~]# ls [123].txt
2.txt 3.txt

1. txt:
[[email protected] ~]# ls [13].txt
3.txt

1. txt:
[[email protected] ~]# ls [23].txt
2.txt 3.txt
[Email protected] ~]#

[[email protected] ~]# ls [0-9a-za-z].txt
2.txt 3.txt

1. txt:
[Email protected] ~]#

[[email protected] ~]# ls {1,2,3,}.txt
LS: Cannot access the. txt: no file or directory
2.txt 3.txt

1. txt:
[Email protected] ~]#

Input and output redirection

[[email protected] ~]# cat 1.txt > 2.txt

[[email protected] ~]# cat 1.txt >> 2.txt

[[email protected] ~]# ls [12].txt aaa.txt &> 2.txt
[[email protected] ~]# ls 2.txt
2.txt

[[email protected] ~]# ls [12].txt aaa.txt &>> 2.txt

[Email protected] ~]# Wc-l < 1.txt

Linux centos7 Shell Introduction, Command history, command completion and aliases, wildcard characters, input and output redirection

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.