1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Shell特殊符号总结以及cut sort wc uniq tee tr split命令

Shell特殊符号总结以及cut sort wc uniq tee tr split命令

时间:2020-09-15 14:39:38

相关推荐

Shell特殊符号总结以及cut sort wc uniq tee tr split命令

独角兽企业重金招聘Python工程师标准>>>

特殊符号总结一

* 任意个任意字符? 任意一个字符# 注释字符\ 脱义字符| 管道符

# #号后的备注被忽略[root@centos01 ~]# ls a.txt # 备注 a.txt[root@centos01 ~]# a=1[root@centos01 ~]# b=2[root@centos01 ~]# c='$a$b'[root@centos01 ~]# echo $c$a$b[root@centos01 ~]# c=\$a\$b # 使用脱义字符[root@centos01 ~]# echo $c$a$b# 管道符综合使用[root@centos01 ~]# cat /etc/passwd | head -n 2root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologin# cut命令# -d指定分隔符 # -f 1 表示取分隔后的第一段值# -f 1,2 表示取1,2段值# -f 1-3 表示取1至3段的值# -c 指定第几个字符[root@centos01 ~]# cat /etc/passwd | head -n 2| cut -d ":" -f 1 rootbin[root@centos01 ~]# cat /etc/passwd | head -n 2| cut -d ":" -f 1,2 root:xbin:x[root@centos01 ~]# cat /etc/passwd | head -n 2| cut -d ":" -f 1,2,3root:x:0bin:x:1[root@centos01 ~]# cat /etc/passwd | head -n 2| cut -d ":" -f 1-3root:x:0bin:x:1[root@centos01 ~]# cat /etc/passwd | head -n 2| cut -c 1rb[root@centos01 ~]# cat /etc/passwd | head -n 2| cut -c 2oi

sort,wc,uniq 命令

sort 排序, -n 以数字排序 -r反序 -t 分隔符 -kn1/-kn1,n2wc -l 统计行数 -m 统计字符数 -w统计词(以空白字符区分词)uniq 去重 -c统计行数tee和>类似,重定向的同时还在屏幕显示, -a 追加tr替换字符, tr 'a' 'b', 大小写替换 tr '[a-z]' '[A-Z]'split 切割 -b大小(默认单位字节), -l行数

[root@centos01 ~]# cat /etc/passwd | head -n 10root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologin[root@centos01 ~]# cat /etc/passwd | head -n 10 | sortadm:x:3:4:adm:/var/adm:/sbin/nologinbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinhalt:x:7:0:halt:/sbin:/sbin/haltlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinmail:x:8:12:mail:/var/spool/mail:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologinroot:x:0:0:root:/root:/bin/bashshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownsync:x:5:0:sync:/sbin:/bin/sync[root@centos01 ~]# cat s.txtroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologin111111122aa12ab1<?>[root@centos01 ~]# sort s.txt -n<>?{adm:x:3:4:adm:/var/adm:/sbin/nologinbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinhalt:x:7:0:halt:/sbin:/sbin/haltlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinmail:x:8:12:mail:/var/spool/mail:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologinroot:x:0:0:root:/root:/bin/bashshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownsync:x:5:0:sync:/sbin:/bin/sync2aa12ab111111112[root@centos01 ~]# cat /etc/passwd | head -n 10 | sort -rsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownroot:x:0:0:root:/root:/bin/bashoperator:x:11:0:operator:/root:/sbin/nologinmail:x:8:12:mail:/var/spool/mail:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinhalt:x:7:0:halt:/sbin:/sbin/haltdaemon:x:2:2:daemon:/sbin:/sbin/nologinbin:x:1:1:bin:/bin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologin[root@centos01 ~]# cat 1.txt1[root@centos01 ~]# cat -A 1.txt # -A查看所有字符,包括隐藏字符1$[root@centos01 ~]# cat wc_test.txtThis is a test file.line 2line 3line 4[root@centos01 ~]# wc wc_test.txt -l4 wc_test.txt[root@centos01 ~]# wc wc_test.txt -w11 wc_test.txt[root@centos01 ~]# wc wc_test.txt -m42 wc_test.txt[root@centos01 ~]# cat uniq_test.txt12,33,44abcab61[root@centos01 ~]# uniq uniq_test.txt # 只去重相邻相同的‘4’,1并没有去重12,33,4abcab61[root@centos01 ~]# sort uniq_test.txt | uniq # 排序后就可以去重了12,33,46ababc[root@centos01 ~]# uniq uniq_test.txt -c1 11 2,1 31 3,2 41 abc1 ab1 61 1[root@centos01 ~]# sort uniq_test.txt |uniq -c2 11 2,1 31 3,2 41 61 ab1 abc[root@centos01 ~]# sort uniq_test.txt |uniq -c > r.log[root@centos01 ~]# sort uniq_test.txt |uniq -c |tee r.log2 11 2,1 31 3,2 41 61 ab1 abc[root@centos01 ~]# echo "centos" | tr '[c]' '[C]'Centos[root@centos01 ~]# echo "centos" | tr '[a-z]' '[A-Z]'CENTOS[root@centos01 ~]# echo "centos" | tr 'c' '1'1entos[root@centos01 t]# ls -lhtotal 224K-rw-r--r--. 1 root root 222K Oct 16 07:55 b.log[root@centos01 t]# split -b 1000 b.log[root@centos01 t]# lsb.log xap xbf xbv xcl xdb xdr xeh xex xfn xgd xgt xhj xhz xipxaa xaq xbg xbw xcm xdc xds xei xey xfo xge xgu xhk xia xiqxab xar xbh xbx xcn xdd xdt xej xez xfp xgf xgv xhl xib xirxac xas xbi xby xco xde xdu xek xfa xfq xgg xgw xhm xic xisxad xat xbj xbz xcp xdf xdv xel xfb xfr xgh xgx xhn xidxae xau xbk xca xcq xdg xdw xem xfc xfs xgi xgy xho xiexaf xav xbl xcb xcr xdh xdx xen xfd xft xgj xgz xhp xifxag xaw xbm xcc xcs xdi xdy xeo xfe xfu xgk xha xhq xigxah xax xbn xcd xct xdj xdz xep xff xfv xgl xhb xhr xihxai xay xbo xce xcu xdk xea xeq xfg xfw xgm xhc xhs xiixaj xaz xbp xcf xcv xdl xeb xer xfh xfx xgn xhd xht xijxak xba xbq xcg xcw xdm xec xes xfi xfy xgo xhe xhu xikxal xbb xbr xch xcx xdn xed xet xfj xfz xgp xhf xhv xilxam xbc xbs xci xcy xdo xee xeu xfk xga xgq xhg xhw ximxan xbd xbt xcj xcz xdp xef xev xfl xgb xgr xhh xhx xinxao xbe xbu xck xda xdq xeg xew xfm xgc xgs xhi xhy xio[root@centos01 t]# wc b.log -l5732 b.log[root@centos01 t]# split -l 1000 b.log split_file[root@centos01 t]# ls -lhtotal 452K-rw-r--r--. 1 root root 222K Oct 16 07:55 b.log-rw-r--r--. 1 root root 44K Oct 16 07:59 split_fileaa-rw-r--r--. 1 root root 44K Oct 16 07:59 split_fileab-rw-r--r--. 1 root root 43K Oct 16 07:59 split_fileac-rw-r--r--. 1 root root 36K Oct 16 07:59 split_filead-rw-r--r--. 1 root root 35K Oct 16 07:59 split_fileae-rw-r--r--. 1 root root 23K Oct 16 07:59 split_fileaf[root@centos01 t]# wc split_fileaa -l1000 split_fileaa

shell 特殊符号总结二

$变量前缀, !$组合, 正则里面表示行尾; 多条命令写到一行用分号分割~用户家目录;正则表达式中表示匹配符& 放到命令后面,会把命令丢到后台> >> 2> 2>> &>[] 指定字符中的一个, 例如[0-9]||和&&, 用于命令之间

[root@centos01 ~]# ls asfasgf.txt || wc -l 1.txt # 只要有一个命令成功,后面的命令就不会再执行 ls: cannot access asfasgf.txt: No such file or directory1 1.txt[root@centos01 ~]# ls asfasgf.txt && wc -l 1.txt # 只有有一个命令失败,后面的所有命令就不会再执行 ls: cannot access asfasgf.txt: No such file or directory[root@centos01 ~]# [ -d test_dir ] || mkdir test_dir # test_dir存在,则不会创建;不存在则创建

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。