10月15日任务linux
8.10 shell特殊符号cut命令正则表达式
8.11 sort_wc_uniq命令shell
8.12 tee_tr_split命令centos
8.13 shell特殊符号下bash
8.10 shell特殊符号cut命令ssh
特殊符号post
*任意个任意字符排序
? 任意一个字符文档
# 注释字符it
\ 脱义字符
| 管道符
[root@centos6 ~]# a=1 [root@centos6 ~]# b=2 [root@centos6 ~]# c=$a$b [root@centos6 ~]# echo $c 12 [root@centos6 ~]# c='$a$b' [root@centos6 ~]# echo $c $a$b [root@centos6 ~]# c=\$a\$b [root@centos6 ~]# echo $c $a$b [root@centos6 ~]# cat /etc/passwd |tail -n2 |cut -d ":" -f 1-4 sshd:x:74:74 ntp:x:38:38
##几个和管道符有关的命令
[root@centos6 ~]# cat /etc/passwd |head -2 root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin [root@centos6 ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1 root bin [root@centos6 ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1,2 root:x bin:x [root@centos6 ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1-3 root:x:0 bin:x:1 [root@centos6 ~]# cat /etc/passwd |head -2 |cut -c 4 t : #sort排序按照阿斯玛排序 [root@centos6 ~]# sort /etc/passwd adm:x:3:4:adm:/var/adm:/sbin/nologin bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin gopher:x:13:30:gopher:/var/gopher:/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 ntp:x:38:38::/etc/ntp:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin root:x:0:0:root:/root:/bin/bash saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin 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 uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
# uniq去重命令使用,只能去掉连续相同的字符 ,常和sort一块儿使用
[root@centos6 ~]# cat 2.txt 1234 1234 12 ab ac ab [root@centos6 ~]# uniq 2.txt 1234 12 ab ac ab [root@centos6 ~]# sort 2.txt |uniq 12 1234 ab ac
#tee命令输出重定向,不只重定向,并且还能打印在在屏幕上。sort、uniq这些命令不会修改原始文档,只会把执行的结果显示出来。
[root@centos6 ~]# sort 2.txt |uniq -c |tee a.txt 1 12 2 1234 2 ab 1 ac [root@centos6 ~]# cat a.txt 1 12 2 1234 2 ab 1 ac [root@centos6 ~]# sort 2.txt |uniq -c |tee -a a.txt 1 12 2 1234 2 ab 1 ac [root@centos6 ~]# cat a.txt 1 12 2 1234 2 ab 1 ac 1 12 2 1234 2 ab 1 ac
#tr命令用法
[root@centos6 ~]# echo "zhangguoxiang" |tr 'z' 'Z' Zhangguoxiang [root@centos6 ~]# echo "zhangguoxiang" |tr '[zgx]' '[ZGX]' ZhanGGuoXianG [root@centos6 ~]# echo "zhangguoxiang" |tr '[a-z]' '[A-Z]' ZHANGGUOXIANG
#split命令用法
[root@centos6 ~]# ls 1.txt 2.txt anaconda-ks.cfg a.txt b.txt install.log install.log.syslog [root@centos6 ~]# split -b 50k a.txt [root@centos6 ~]# ls 1.txt anaconda-ks.cfg b.txt install.log.syslog xab xad 2.txt a.txt install.log xaa xac [root@centos6 ~]# split -b 50k a.txt abc. [root@centos6 ~]# ls 1.txt abc.aa abc.ac anaconda-ks.cfg b.txt install.log.syslog xab xad 2.txt abc.ab abc.ad a.txt install.log xaa xac
8.1三、shell特殊符号
特俗符号
$变量前缀,!$组合,正则里面表示行尾
;多条命令写到一行,用分号分割
~用户家目录,后面正则表达式表示匹配符
&放到命令后面,会把命令丢到后台
> 覆盖 >> 追加 2> 错误覆盖 2>> 错误追加 &>不区分,会把正确和错误的同事覆盖到文件
[]指定字符中的一个,[0-9],[a-z],[A-Z],[abc]
||(表示或,前边命令执行不成功执行后边一条,前边命令正确就爱不在执行后边命令)和&&(表示且,前边一条执行成功才会执行后边命令),用于命令之间
示例:[root@centos6 ~]# ls 1.txt ;wc -l 2.txt 1.txt 6 2.txt [root@centos6 ~]# ls 1a.txt ||wc -l 2.txt ls: cannot access 1a.txt: No such file or directory 6 2.txt [root@centos6 ~]# ls 1.txt ||2.txt 1.txt [root@centos6 ~]# ls 1a.txt &&wc -l 2.txt ls: cannot access 1a.txt: No such file or directory [root@centos6 ~]# ls 1.txt &&wc -l 2.txt 1.txt 6 2.txt [root@centos6 ~]# ls -d aminglinux ||mkdir aminglinux #本身瞎写的方法 ls: cannot access aminglinux: No such file or directory [root@centos6 ~]# ls 1.txt abc.aa abc.ac aminglinux a.txt install.log xaa xac 2.txt abc.ab abc.ad anaconda-ks.cfg b.txt install.log.syslog xab xad [root@centos6 ~]# ls -d aminglinux ||mkdir aminglinux aminglinux [root@centos6 ~]# [ -d zgxlinux ] ||mkdir zgxlinux #老师方法 [root@centos6 ~]# ls 1.txt abc.ab aminglinux b.txt xaa xad 2.txt abc.ac anaconda-ks.cfg install.log xab zgxlinux abc.aa abc.ad a.txt install.log.syslog xac [root@centos6 ~]# [ -d zgxlinux ] &&mkdir zgxlinux mkdir: cannot create directory `zgxlinux': File exists