系统符号内容概述
系统基础符号
系统通配符号
系统正则符号
a 基础正则符号
b 扩展正则符号
一系统基础符号
(一)美元符号:$
取出变量中的内容
[root@centos71 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@centos71 ~]#
用于取出指定列的信息
[root@centos71 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 41922560 4585576 37336984 11% /
devtmpfs 487064 0 487064 0% /dev
tmpfs 497960 0 497960 0% /dev/shm
tmpfs 497960 7860 490100 2% /run
tmpfs 497960 0 497960 0% /sys/fs/cgroup
/dev/sda1 201380 107080 94300 54% /boot
tmpfs 99596 0 99596 0% /run/user/0
[root@centos71 ~]# df | awk -F" " '{print $1}'
Filesystem
/dev/sda3
devtmpfs
tmpfs
tmpfs
tmpfs
/dev/sda1
tmpfs
表示超级用户命令提示符号为#
[root@centos71 ~]# su - wang
Last login: Tue Dec 17 11:19:45 CST 2019 on pts/0
____________
< hahahahaha >
------------
___ _____ ___
/ / /| /
| | / / | | |
| | /____/ | | |
| | | | | | |
| | | {} | / | |
| | |____|/ | |
| | |==| | |
| \___________/ |
| |
| |
[wang@centos71 ~]$ whoami
wang
[wang@centos71 ~]$ echo $PS1
[u@h W]$
表示一行的结尾
[root@centos71 ~]# cat -A /etc/selinux/config
$
# This file controls the state of SELinux on the system.$
# SELINUX= can take one of these three values:$
# enforcing - SELinux security policy is enforced.$
# permissive - SELinux prints warnings instead of enforcing.$
# disabled - No SELinux policy is loaded.$
SELINUX=disabled$
# SELINUXTYPE= can take one of three values:$
# targeted - Targeted processes are protected,$
# minimum - Modification of targeted policy. Only selected processes are protected. $
# mls - Multi Level Security protection.$
SELINUXTYPE=targeted$
$
$
(二)叹号符号:!
用于取反或者排除
[root@centos71 ~]# find /etc/sysconfig/network-scripts/ -type f ! -name "^ifcfg**"
/etc/sysconfig/network-scripts/ifcfg-lo
/etc/sysconfig/network-scripts/ifdown-bnep
/etc/sysconfig/network-scripts/ifdown-eth
/etc/sysconfig/network-scripts/ifdown-ippp
/etc/sysconfig/network-scripts/ifdown-ipv6
/etc/sysconfig/network-scripts/ifdown-post
/etc/sysconfig/network-scripts/ifdown-ppp
/etc/sysconfig/network-scripts/ifdown-routes
/etc/sysconfig/network-scripts/ifdown-sit
/etc/sysconfig/network-scripts/ifdown-tunnel
/etc/sysconfig/network-scripts/ifup-aliases
/etc/sysconfig/network-scripts/ifup-bnep
/etc/sysconfig/network-scripts/ifup-eth
/etc/sysconfig/network-scripts/ifup-ippp
/etc/sysconfig/network-scripts/ifup-ipv6
/etc/sysconfig/network-scripts/ifup-plip
/etc/sysconfig/network-scripts/ifup-plusb
/etc/sysconfig/network-scripts/ifup-post
/etc/sysconfig/network-scripts/ifup-ppp
/etc/sysconfig/network-scripts/ifup-routes
/etc/sysconfig/network-scripts/ifup-sit
/etc/sysconfig/network-scripts/ifup-tunnel
/etc/sysconfig/network-scripts/ifup-wireless
/etc/sysconfig/network-scripts/init.ipv6-global
/etc/sysconfig/network-scripts/network-functions
/etc/sysconfig/network-scripts/network-functions-ipv6
/etc/sysconfig/network-scripts/ifdown-Team
/etc/sysconfig/network-scripts/ifdown-TeamPort
/etc/sysconfig/network-scripts/ifup-Team
/etc/sysconfig/network-scripts/ifup-TeamPort
/etc/sysconfig/network-scripts/ifcfg-eth0
命令行中调取最近命令
慎用,因为不知道会执行什么
[root@centos71 ~]# !cat
cat -A /etc/selinux/config
$
# This file controls the state of SELinux on the system.$
# SELINUX= can take one of these three values:$
# enforcing - SELinux security policy is enforced.$
# permissive - SELinux prints warnings instead of enforcing.$
# disabled - No SELinux policy is loaded.$
SELINUX=disabled$
# SELINUXTYPE= can take one of three values:$
# targeted - Targeted processes are protected,$
# minimum - Modification of targeted policy. Only selected processes are protected. $
# mls - Multi Level Security protection.$
SELINUXTYPE=targeted$
$
$
用于表示强制操作处理
vim底行模式保存退出
wq!
q!
(三)竖线符号:|
表示管道符号,管道前面命令,交给管道后面执行
经常配合xargs命令使用
查找指定数据信息进行复制
[root@centos71 ~]# mkdir /test2
[root@centos71 ~]# ls /test2
[root@centos71 ~]# find /etc/ -type f -name "m*.conf"
/etc/libreport/events.d/mailx_event.conf
/etc/libreport/plugins/mantisbt.conf
/etc/libreport/plugins/mantisbt_format.conf
/etc/libreport/plugins/mantisbt_format_analyzer_libreport.conf
/etc/libreport/plugins/mantisbt_formatdup.conf
/etc/libreport/plugins/mantisbt_formatdup_analyzer_libreport.conf
/etc/libreport/plugins/mailx.conf
/etc/ld.so.conf.d/mariadb-x86_64.conf
/etc/man_db.conf
/etc/mke2fs.conf
[root@centos71 ~]# find /etc/ -type f -name "m*.conf" | xargs -i cp {} /test2
[root@centos71 ~]# ls /test2
mailx.conf mantisbt_format_analyzer_libreport.conf mariadb-x86_64.conf
mailx_event.conf mantisbt_format.conf mke2fs.conf
man_db.conf mantisbt_formatdup_analyzer_libreport.conf
mantisbt.conf mantisbt_formatdup.conf
[root@centos71 ~]# ls /test2
[root@centos71 ~]# find /etc/ -type f -name "m*.conf" | xargs cp -t /test2
[root@centos71 ~]# ls /test2
mailx.conf mantisbt_format_analyzer_libreport.conf mariadb-x86_64.conf
mailx_event.conf mantisbt_format.conf mke2fs.conf
man_db.conf mantisbt_formatdup_analyzer_libreport.conf
mantisbt.conf mantisbt_formatdup.conf
查找指定数据信息进行移动
[root@centos71 ~]# find /test2 -type f -name "m*.conf"
/test2/mailx_event.conf
/test2/mantisbt.conf
/test2/mantisbt_format.conf
/test2/mantisbt_format_analyzer_libreport.conf
/test2/mantisbt_formatdup.conf
/test2/mantisbt_formatdup_analyzer_libreport.conf
/test2/mailx.conf
/test2/mariadb-x86_64.conf
/test2/man_db.conf
/test2/mke2fs.conf
[root@centos71 ~]# find /test2 -type f -name "m*.conf" | xargs mv -t /test
[root@centos71 ~]# ls /test
mailx.conf mantisbt_format_analyzer_libreport.conf mariadb-x86_64.conf
mailx_event.conf mantisbt_format.conf mke2fs.conf
man_db.conf mantisbt_formatdup_analyzer_libreport.conf
mantisbt.conf mantisbt_formatdup.conf
[root@centos71 ~]# ls /test2
[root@centos71 ~]# find /test -type f -name "m*.conf" | xargs -i mv {} /test2
[root@centos71 ~]# ls /test2
mailx.conf mantisbt_format_analyzer_libreport.conf mariadb-x86_64.conf
mailx_event.conf mantisbt_format.conf mke2fs.conf
man_db.conf mantisbt_formatdup_analyzer_libreport.conf
mantisbt.conf mantisbt_formatdup.conf
[root@centos71 ~]# ls /test
查找指定数据信息进行删除
删除不需要{ }
[root@centos71 ~]# find /test2 -type f -name "m*.conf" | xargs rm
[root@centos71 ~]# ls /test2
(四)井号符号:#
表示文件内容注释符号
[root@centos71 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
表示超级用户命令提示符号
[root@centos71 ~]# whoami
root
[root@centos71 ~]# pwd
/root
二引号符号系列
" " 将指定信息进行输出显示,解析输出特殊字符信息
[root@centos71 ~]# echo "$PATH `which cat`"
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin /usr/bin/cat
' ' 将指定信息进行输出显示,所见即所得
[root@centos71 ~]# echo '$PATH `which cat`'
$PATH `which cat`
反引号 `` : 表示命令执行结果留下,用于其他命令调用
[root@centos71 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@centos71 ~]# echo `echo $PATH`
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@centos71 ~]# echo $(echo $PATH)
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
没有引号 : 和双引号功能是类似,可以输出序列信息
数字序列
[root@centos71 ~]# echo {01..10}
01 02 03 04 05 06 07 08 09 10
字母序列
[root@centos71 ~]# echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z
生成奇数序列/偶数序列
[root@centos71 ~]# echo {01..20..2}
01 03 05 07 09 11 13 15 17 19
[root@centos71 ~]# echo {02..20..2}
02 04 06 08 10 12 14 16 18 20
三定向符号系列
小于符号
单个小于符号 <
标准输入重定向符号
[root@centos71 ~]# xargs -n2 < /etc/hosts
127.0.0.1 localhost
localhost.localdomain localhost4
localhost4.localdomain4 ::1
localhost localhost.localdomain
localhost6 localhost6.localdomain6
两个小于符号 <<
标准输入追加重定向符号
[root@centos71 ~]# cat >> aa.txt <<EOF
> abcd
> asd
> afc
> afar
> afg
> aafg
> EOF
[root@centos71 ~]# cat aa.txt
abcd
asd
afc
afar
afg
aafg
大于符号
单个大于符号 >
1>/>标准输出重定向符号
清空文件内容
[root@centos71 ~]# cat aa.txt
abcd
asd
afc
afar
afg
aafg
1234
[root@centos71 ~]# > aa.txt
[root@centos71 ~]# cat aa.txt
2>错误输出重定向符号
看返回值可以看出是报错结果
[root@centos71 ~]# ech hahahahaha 2> fail.txt
[root@centos71 ~]# echo $?
127
[root@centos71 ~]# cat fail.txt
-bash: ech: command not found
[root@centos71 ~]#
两个大于符号
1>>/>>标准输出追加重定向符号
向文件末尾添加空行
[root@centos71 ~]# cat /etc/selinux/config | wc
14 81 541
[root@centos71 ~]# echo >> /etc/selinux/config
[root@centos71 ~]# cat /etc/selinux/config | wc
15 81 542
[root@centos71 ~]# tail -1 /etc/selinux/config
[root@centos71 ~]# tail -1 /etc/selinux/config | wc
1 0 1
2>>错误输出追加重定向符号
[root@centos71 ~]# cat fail.txt
-bash: ech: command not found
[root@centos71 ~]# touc hahahaha.txt 2>> fail.txt
[root@centos71 ~]# cat fail.txt
-bash: ech: command not found
-bash: touc: command not found
四路径符号系列
(一)单点符号:./ 表示当前目录
[root@centos71 ~]# cd ./
[root@centos71 ~]# pwd
/root
[root@centos71 ~]# cd .
[root@centos71 ~]# pwd
/root
(二)双点符号:cd .. 表示上级目录
[root@centos71 ~]# cd ..
[root@centos71 /]# pwd
/
(三)波浪符号: cd ~ 表示用户家目录
超级用户:/root
普通用户:/home/用户名称
[wang@centos71 ~]$ pwd
/home/wang
[wang@centos71 ~]$ cd ~
[wang@centos71 ~]$ pwd
/home/wang
[root@centos71 ~]# pwd
/root
[root@centos71 ~]# cd ~
[root@centos71 ~]# pwd
/root
(四)- : 上一次所在目录
横线符号:cd - 两个目录路间进行切换
OLDPWD: 保存用户切换目录之前的所在路径信息
An argu‐
ment of - is equivalent to $OLDPWD.
[root@centos71 ~]# pwd
/root
[root@centos71 ~]# cd -
/root
[root@centos71 ~]# cd /etc/
[root@centos71 etc]# echo $OLDPWD
/root
[root@centos71 etc]# cd -
/root
[root@centos71 ~]# echo $OLDPWD
/etc
[root@centos71 ~]# cd -
/etc
五逻辑符号系列
(一)&& 与
前一件事执行成功了, 在执行&& 后面的命令
前一个事情成功完成了, 再做下一件事情
[root@centos71 ~]# cp /etc/hosts /backup/hosts.bak && echo "备份成功"
备份成功
(二)|| 或
前一件事执行失败了就会执行|| 后面的命令
[root@centos71 ~]# tou ooooo.txt || pwd
-bash: tou: command not found
/root
(三);分号
不管前面命令成功与否,都会执行;后面的命令
[root@centos71 ~]# ech 1234 ; pwd;whoami
-bash: ech: command not found
/root
root
六系统通配符号
(一)*匹配任意字符或者字符串
[root@centos71 ~]# ls -d /etc/sysconfig/network*
/etc/sysconfig/network /etc/sysconfig/network-scripts
[root@centos71 ~]# ls /etc/sysconfig/network-scripts/*
/etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifup-eth
/etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifup-ippp
/etc/sysconfig/network-scripts/ifdown /etc/sysconfig/network-scripts/ifup-ipv6
/etc/sysconfig/network-scripts/ifdown-bnep /etc/sysconfig/network-scripts/ifup-isdn
/etc/sysconfig/network-scripts/ifdown-eth /etc/sysconfig/network-scripts/ifup-plip
/etc/sysconfig/network-scripts/ifdown-ippp /etc/sysconfig/network-scripts/ifup-plusb
/etc/sysconfig/network-scripts/ifdown-ipv6 /etc/sysconfig/network-scripts/ifup-post
/etc/sysconfig/network-scripts/ifdown-isdn /etc/sysconfig/network-scripts/ifup-ppp
/etc/sysconfig/network-scripts/ifdown-post /etc/sysconfig/network-scripts/ifup-routes
/etc/sysconfig/network-scripts/ifdown-ppp /etc/sysconfig/network-scripts/ifup-sit
/etc/sysconfig/network-scripts/ifdown-routes /etc/sysconfig/network-scripts/ifup-Team
/etc/sysconfig/network-scripts/ifdown-sit /etc/sysconfig/network-scripts/ifup-TeamPort
/etc/sysconfig/network-scripts/ifdown-Team /etc/sysconfig/network-scripts/ifup-tunnel
/etc/sysconfig/network-scripts/ifdown-TeamPort /etc/sysconfig/network-scripts/ifup-wireless
/etc/sysconfig/network-scripts/ifdown-tunnel /etc/sysconfig/network-scripts/init.ipv6-global
/etc/sysconfig/network-scripts/ifup /etc/sysconfig/network-scripts/network-functions
/etc/sysconfig/network-scripts/ifup-aliases /etc/sysconfig/network-scripts/network-functions-ipv6
/etc/sysconfig/network-scripts/ifup-bnep
(二){ }匹配生成序列
数字序列
[root@centos71 ~]# echo {01..10}
01 02 03 04 05 06 07 08 09 10
[root@centos71 ~]# echo {01..20}
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
[root@centos71 ~]# echo {1..30}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
奇数序列
[root@centos71 ~]# echo {01..10..2}
01 03 05 07 09
[root@centos71 ~]# echo {01..30..3}
01 04 07 10 13 16 19 22 25 28
[root@centos71 ~]# echo {01..100..4}
001 005 009 013 017 021 025 029 033 037 041 045 049 053 057 061 065 069 073 077 081 085 089 093 097
偶数序列
[root@centos71 ~]# echo {2..100..4}
2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98
[root@centos71 ~]# echo {00..10..4}
00 04 08
[root@centos71 ~]# echo {00..10..2}
00 02 04 06 08 10
[root@centos71 ~]# echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z
组合序列:
[root@centos71 ~]# echo 1{a..d}
1a 1b 1c 1d
[root@centos71 ~]# echo {1..6}{a..f}
1a 1b 1c 1d 1e 1f 2a 2b 2c 2d 2e 2f 3a 3b 3c 3d 3e 3f 4a 4b 4c 4d 4e 4f 5a 5b 5c 5d 5e 5f 6a 6b 6c 6d 6e 6f
[root@centos71 ~]# echo {1..6}a
1a 2a 3a 4a 5a 6a
[root@centos71 ~]# echo A{A,B}
AA AB
[root@centos71 ~]# echo A{,B}
A AB
[root@centos71 test]# ls english_words.txt*
english_words.txt english_words.txt.bak
[root@centos71 test]# rm -f english_words.txt
[root@centos71 test]# ls english_words.txt*
english_words.txt.bak
[root@centos71 test]# cp english_words.txt{.bak,}
[root@centos71 test]# ls english_words.txt*
english_words.txt english_words.txt.bak
七正则符号
通配符和正则符合的区别:
通配符号主要匹配的是文件名称
正则符号主要用于匹配字符、文件内容,只有文本处理三剑客(grep sed awk)可以识别,可以用于分析数据
过滤掉空行和注释
[root@centos71 ~]# grep -Ev "^$|^#" /etc/ssh/sshd_config
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
SyslogFacility AUTHPRIV
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication yes
ChallengeResponseAuthentication no
GSSAPIAuthentication no
GSSAPICleanupCredentials no
UsePAM yes
X11Forwarding yes
UseDNS no
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
Subsystem sftp /usr/libexec/openssh/sftp-server
要使用到扩展的正则表达式
-E, --extended-regexp
Interpret PATTERN as an extended regular expression (ERE, see below). (-E is specified
by POSIX.)
过滤掉注释
[root@centos71 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@centos71 ~]# grep "^#" /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
[root@centos71 ~]# grep "^S" /etc/selinux/config
SELINUX=disabled
SELINUXTYPE=targeted
[root@centos71 ~]# grep -i "^s" /etc/selinux/config
SELINUX=disabled
SELINUXTYPE=targeted
查看行尾是否有空格
方法一:cat -A
[root@centos71 ~]# grep "d$" /etc/selinux/config
SELINUX=disabled
[root@centos71 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@centos71 ~]# cat -A /etc/selinux/config
$
# This file controls the state of SELinux on the system.$
# SELINUX= can take one of these three values:$
# enforcing - SELinux security policy is enforced.$
# permissive - SELinux prints warnings instead of enforcing.$
# disabled - No SELinux policy is loaded.$
SELINUX=disabled$
# SELINUXTYPE= can take one of three values:$
# targeted - Targeted processes are protected,$
# minimum - Modification of targeted policy. Only selected processes are protected. $
# mls - Multi Level Security protection.$
SELINUXTYPE=targeted $
$
$
[root@centos71 ~]#
方法二:打开文件,在底行模式下输入set list
[root@centos71 ~]# cat -A /etc/selinux/config
$
# This file controls the state of SELinux on the system.$
# SELINUX= can take one of these three values:$
# enforcing - SELinux security policy is enforced.$
# permissive - SELinux prints warnings instead of enforcing.$
# disabled - No SELinux policy is loaded.$
SELINUX=disabled$
# SELINUXTYPE= can take one of three values:$
# targeted - Targeted processes are protected,$
# minimum - Modification of targeted policy. Only selected processes are protected. $
# mls - Multi Level Security protection.$
SELINUXTYPE=targeted$
$
$
[root@centos71 ~]# grep "d$" /etc/selinux/config
SELINUX=disabled
SELINUXTYPE=targeted
[root@centos71 ~]# grep -v "^$" /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@centos71 ~]# grep -v "^$" /etc/selinux/config | cat -A
# This file controls the state of SELinux on the system.$
# SELINUX= can take one of these three values:$
# enforcing - SELinux security policy is enforced.$
# permissive - SELinux prints warnings instead of enforcing.$
# disabled - No SELinux policy is loaded.$
SELINUX=disabled$
# SELINUXTYPE= can take one of three values:$
# targeted - Targeted processes are protected,$
# minimum - Modification of targeted policy. Only selected processes are protected. $
# mls - Multi Level Security protection.$
SELINUXTYPE=targeted$