shell特殊字符
2018-01-12 23:49
232 查看
特殊符号
通配符,任意个字符
? 任意个字符
.#注释字符
\ 脱义字符
cut 选取信息,针对行进行分析
主要参数
-b :以字节为单位进行分割。这些字节位置将忽略多字节字符边界,除非也指定了 -n 标志。
-c :以字符为单位进行分割。
-d :自定义分隔符,默认为制表符。
-f :与-d一起使用,指定显示哪个区域。
-n :取消分割多字节字符。仅和 -b 标志一起使用。如果字符的最后一个字节落在由 -b 标志的 List 参数指示的<br />范围之内,该字符将被写出;否则,该字符将被排除。
adm:x:3:4:adm:/var/adm:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
halt:x:7:0:halt:/sbin:/sbin/halt
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
root:x:0:0:root:/root:/bin/bash
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
sort -r 倒序
[root@aminglinux01 ~]# wc -l 1.txt
29 1.txt
[root@aminglinux01 ~]# wc -m 1.txt
468 1.txt
[root@aminglinux01 ~]# wc -w 1.txt
27 1.txt
uniq 排序 -c 去重
[root@aminglinux01 ~]# sort 2.txt
1
1
1
123
123
2
2
2
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
3
abc
abc 1111,222
[root@aminglinux01 ~]# sort 2.txt | uniq
1
123
2
21
3
abc
abc 1111,222
[root@aminglinux01 ~]# sort 2.txt | uniq -c
3 1
2 123
3 2
21 21
1 3
1 abc
1 abc 1111,222
[root@aminglinux01 ~]# cat a.txt #查看
[root@aminglinux01 ~]# sort 2.txt | uniq -c | tee a.txt #重定向并显示
3 1
2 123
3 2
21 21
1 3
1 abc
1 abc 1111,222
[root@aminglinux01 ~]# cat a.txt
3 1
2 123
3 2
21 21
1 3
1 abc
1 abc 1111,222
[root@aminglinux01 ~]# sort 2.txt | uniq -c | tee -a a.txt #追加
3 1
2 123
3 2
21 21
1 3
1 abc
1 abc 1111,222
[root@aminglinux01 ~]# cat a.txt #查看内容
2 123
3 2
21 21
1 3
1 abc
1 abc 1111,222
3 1
2 123
3 2
21 21
1 3
1 abc
1 abc 1111,222
AmingLinux
[root@aminglinux01 ~]# echo "aminglinux" |tr 'a' 'A'
Aminglinux
[root@aminglinux01 test]# ls
a.txt xaa xab
[root@aminglinux01 test]# du -sh
128K a.txt
100K xaa
28K xab
[root@aminglinux01 test]# split -b 100k a.txt abc. #指定大小
[root@aminglinux01 test]# ls
abc.aa abc.ab a.txt
[root@aminglinux01 test]# split -l 1000 a.txt #指定行
[root@aminglinux01 test]# ls -l
总用量 260
-rw-r--r--. 1 root root 129633 1月 13 07:31 a.txt
-rw-r--r--. 1 root root 41537 1月 13 07:32 xaa
-rw-r--r--. 1 root root 35466 1月 13 07:32 xab
-rw-r--r--. 1 root root 36841 1月 13 07:32 xac
-rw-r--r--. 1 root root 15789 1月 13 07:32 xad
[root@aminglinux01 test]# wc -l
3549 a.txt
1000 xaa
1000 xab
1000 xac
549 xad
7098 总用量
!$组合,正则里面表示行尾
;多行命令写到一行,用;分割
~用户家目录,正则表达式表示匹配符
&放在命令后,会把命令挂起在后台
>> 2> 2>> &>
[] 指定字符的一个,[0-9][a-z][A-Z]
1.txt
32 2.txt
[root@aminglinux01 ~]# ls 1.txt || wc -l 2.txt
1.txt
当前面命令成功,不执行后面的命令
[root@aminglinux01 ~]# ls 1.txt && wc -l 2.txt
1.txt
32 2.txt
[root@aminglinux01 ~]# ls 1a.txt && wc -l 2.txt
ls: 无法访问1a.txt: 没有那个文件或目录
当前面的命令不成功,不执行后面的命令
[root@aminglinux01 ~]# [ -d aminglinux ] || mkdir aminglinux
如果aminglinux 目录不存在,就创建aminglinux目录
[-d n]固定格式
[root@aminglinux01 ~]# ls
1.txt 2.txt 3.txt aaaa.txt aminglinux anaconda-ks.cfg a.txt; :q test
[root@aminglinux01 ~]# [ -d aminglinux ] && mkdir aminglinux
mkdir: 无法创建目录"aminglinux": 文件已存在
[root@aminglinux01 ~]# [ -d aminglinux ] || mkdir aminglinux
通配符,任意个字符
? 任意个字符
.#注释字符
\ 脱义字符
| 管道
几个和管道有关的命令cut 选取信息,针对行进行分析
主要参数
-b :以字节为单位进行分割。这些字节位置将忽略多字节字符边界,除非也指定了 -n 标志。
-c :以字符为单位进行分割。
-d :自定义分隔符,默认为制表符。
-f :与-d一起使用,指定显示哪个区域。
-n :取消分割多字节字符。仅和 -b 标志一起使用。如果字符的最后一个字节落在由 -b 标志的 List 参数指示的<br />范围之内,该字符将被写出;否则,该字符将被排除。
sort 排序,默认以ASC码排序
[root@aminglinux01 ~]# sort /etc/passwdadm:x:3:4:adm:/var/adm:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
halt:x:7:0:halt:/sbin:/sbin/halt
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
root:x:0:0:root:/root:/bin/bash
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
sort -r 倒序
wc 统计
-l 统计行数 -m 统计字符数 -w 统计词[root@aminglinux01 ~]# wc -l 1.txt
29 1.txt
[root@aminglinux01 ~]# wc -m 1.txt
468 1.txt
[root@aminglinux01 ~]# wc -w 1.txt
27 1.txt
uniq 排序 -c 去重
[root@aminglinux01 ~]# sort 2.txt
1
1
1
123
123
2
2
2
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
3
abc
abc 1111,222
[root@aminglinux01 ~]# sort 2.txt | uniq
1
123
2
21
3
abc
abc 1111,222
[root@aminglinux01 ~]# sort 2.txt | uniq -c
3 1
2 123
3 2
21 21
1 3
1 abc
1 abc 1111,222
tee和 >输出重定向类似
[root@aminglinux01 ~]# >a.txt #清空a.txt内容[root@aminglinux01 ~]# cat a.txt #查看
[root@aminglinux01 ~]# sort 2.txt | uniq -c | tee a.txt #重定向并显示
3 1
2 123
3 2
21 21
1 3
1 abc
1 abc 1111,222
[root@aminglinux01 ~]# cat a.txt
3 1
2 123
3 2
21 21
1 3
1 abc
1 abc 1111,222
[root@aminglinux01 ~]# sort 2.txt | uniq -c | tee -a a.txt #追加
3 1
2 123
3 2
21 21
1 3
1 abc
1 abc 1111,222
[root@aminglinux01 ~]# cat a.txt #查看内容
2 123
3 2
21 21
1 3
1 abc
1 abc 1111,222
3 1
2 123
3 2
21 21
1 3
1 abc
1 abc 1111,222
tr 替换字符
[root@aminglinux01 ~]# echo "aminglinux" |tr '[al]' '[AL]'AmingLinux
[root@aminglinux01 ~]# echo "aminglinux" |tr 'a' 'A'
Aminglinux
split 切割
[root@aminglinux01 test]# split -b 100k a.txt[root@aminglinux01 test]# ls
a.txt xaa xab
[root@aminglinux01 test]# du -sh
128K a.txt
100K xaa
28K xab
[root@aminglinux01 test]# split -b 100k a.txt abc. #指定大小
[root@aminglinux01 test]# ls
abc.aa abc.ab a.txt
[root@aminglinux01 test]# split -l 1000 a.txt #指定行
[root@aminglinux01 test]# ls -l
总用量 260
-rw-r--r--. 1 root root 129633 1月 13 07:31 a.txt
-rw-r--r--. 1 root root 41537 1月 13 07:32 xaa
-rw-r--r--. 1 root root 35466 1月 13 07:32 xab
-rw-r--r--. 1 root root 36841 1月 13 07:32 xac
-rw-r--r--. 1 root root 15789 1月 13 07:32 xad
[root@aminglinux01 test]# wc -l
3549 a.txt
1000 xaa
1000 xab
1000 xac
549 xad
7098 总用量
特殊符号
$变量前缀!$组合,正则里面表示行尾
;多行命令写到一行,用;分割
~用户家目录,正则表达式表示匹配符
&放在命令后,会把命令挂起在后台
>> 2> 2>> &>
[] 指定字符的一个,[0-9][a-z][A-Z]
||和&& 用于命令中间的逻辑关系
[root@aminglinux01 ~]# ls 1.txt ;wc -l 2.txt1.txt
32 2.txt
[root@aminglinux01 ~]# ls 1.txt || wc -l 2.txt
1.txt
当前面命令成功,不执行后面的命令
[root@aminglinux01 ~]# ls 1.txt && wc -l 2.txt
1.txt
32 2.txt
[root@aminglinux01 ~]# ls 1a.txt && wc -l 2.txt
ls: 无法访问1a.txt: 没有那个文件或目录
当前面的命令不成功,不执行后面的命令
[root@aminglinux01 ~]# [ -d aminglinux ] || mkdir aminglinux
如果aminglinux 目录不存在,就创建aminglinux目录
[-d n]固定格式
[root@aminglinux01 ~]# ls
1.txt 2.txt 3.txt aaaa.txt aminglinux anaconda-ks.cfg a.txt; :q test
[root@aminglinux01 ~]# [ -d aminglinux ] && mkdir aminglinux
mkdir: 无法创建目录"aminglinux": 文件已存在
[root@aminglinux01 ~]# [ -d aminglinux ] || mkdir aminglinux
相关文章推荐
- shell 对应特殊字符
- shell中的特殊字符【3】
- shell 知识点补充(1)-提示字符的设定/read/declare / typeset/变量设定功能/别名/万用字符与特殊符号
- Shell 特殊字符
- shell学习之-特殊字符
- shell 笔记 特殊变量 特殊字符 Metacharacters
- shell 脚本之特殊变量字符
- shell分割字符串函数(支持特殊字符和不可见字符)
- shell中的特殊字符【1】
- Shell中有特殊含义的字符
- shell中的特殊字符
- shell里面的特殊字符
- shell中特殊字符的意思
- Shell特殊字符(上)
- Linux CentOS 7 shell中的特殊字符及与管道相关的命令(cut,sort,wc,uniq,tee,tr,split)
- Shell中有特殊含义的字符
- shell高级编程(2)——特殊字符
- shell中常用的特殊字符
- Linux下高效编写Shell―shell特殊字符汇总
- Shell变量名使用的特殊字符