码迷,mamicode.com
首页 > 系统相关 > 详细

shell特殊符号,wc,uniq,tee_tr_split命令

时间:2017-11-18 12:42:31      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:shell特殊符号   uniq   wc   tee_tr_split命令   

[root@abinlinux ~]# cut -d: -f 3 /etc/passwd   -d:分隔符    -f 加数字第几段     f是第几段

0

1

2

[root@abinlinux ~]# cut -d: -f 3,4,5,6,7 /etc/passwd  可以多选几段加,号就可以

0:0:root:/root:/bin/bash

1:1:bin:/bin:/sbin/nologin

2:2:daemon:/sbin:/sbin/nologin

3:4:adm:/var/adm:/sbin/nologin

[root@abinlinux ~]# cut -c 10 /etc/passwd    -c是第几个字符    c10就是第十个字符

0

:

2

[root@abinlinux ~]# cut -c 1-10 /etc/passwd    第一个到第十个  字符  -c是区间第几个

root:x:0:0

bin:x:1:1:

daemon:x:2



[root@abinlinux ~]# sort /etc/passwd    默认排序  阿斯玛排序

adm:x:3:4:adm:/var/adm:/sbin/nologin

apache:x:48:48:Apache:/var/www:/sbin/nologin

bin:x:1:1:bin:/bin:/sbin/nologin

daemon:x:2:2:daemon:/sbin:/sbin/nologin

[root@abinlinux ~]# sort -t: -k3 /etc/passwd     -t:是分隔符  -k3 是第三段  排序

root:x:0:0:root:/root:/bin/bash

uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin

operator:x:11:0:operator:/root:/sbin/nologin

bin:x:1:1:bin:/bin:/sbin/nologin

[root@abinlinux ~]# sort -t: -k3 -n /etc/passwd   -n 按数字排序   也可以-k 3,6  区间值

root:x:0:0:root:/root:/bin/bash

bin:x:1:1:bin:/bin:/sbin/nologin

daemon:x:2:2:daemon:/sbin:/sbin/nologin

adm:x:3:4:adm:/var/adm:/sbin/nologin

[root@abinlinux ~]# sort -t: -k3,5 -n -r /etc/passwd      -r 是反序

yun:x:500:500::/home/yun:/bin/bash

saslauth:x:499:76:Saslauthd user:/var/empty/saslauth

bin:x:1:1:bin:/bin:/sbin/nologin

root:x:0:0:root:/root:/bin/bash

[root@abinlinux ~]# sort -t: -k 3,5 -n -r -u /etc/passwd   -u是去重复的 意思

sort -un 2.txt       也可以这样用


[root@abinlinux ~]# uniq -c 2.txt       加选项 -c 列出重复

1 1

1 2

1 3

2 4

1 5

2 6

1 7

2 8

2 9

[root@abinlinux ~]# sort 2.txt |uniq -c   排下序在去去重复

1 1

1 10

1 12

1 1212

1 12166

1 2

1 3

2 4

1 5

2 6

1 7

2 8

2 9

[root@abinlinux ~]# echo "1111111"  |tee 1.txt   tee的用法

1111111

[root@abinlinux ~]# echo "1111111"  |tee 1.txt

1111111

[root@abinlinux ~]# cat 1.txt

1111111


[root@abinlinux ~]# ls *.txt |tr ‘a-z‘ ‘A-Z‘    .txt变成大写 字母名字变成大写  tr替换字符

1.TXT

2.TXT

C.TXT

M.TXT

Z.TXT

[root@abinlinux ~]# echo $ "jksadhasjkdh" |tr ‘j‘ ‘E‘     替换大小写 字符

$ EksadhasEkdh

[root@abinlinux ~]# echo "jksadhasjkdh" |tr ‘j‘ ‘E‘

EksadhasEkdh

[root@abinlinux ~]# echo "jksadhasjkdh" |tr ‘a-z‘ ‘A-Z‘  全局替换     也可以范围缩小 ‘a-f’

JKSADHASJKDH

split  切割日志的

[root@abinlinux ~]# split -l 10 anaconda-ks.cfg      -l分多少行

[root@abinlinux ~]# ls

12               c.txt                   link     xaa   xab  

12.tar           install.log             m.txt    xac  

1.txt            install.log.syslog      wps     xad

[root@abinlinux ~]# du -sb anaconda-ks.cfg    查看大小

1028    anaconda-ks.cfg

[root@abinlinux ~]# split -b 100 anaconda-ks.cfg        -b 以100b切割

[root@abinlinux ~]# ls -lh xa*

-rw-r--r-- 1 root root 100 10月 27 07:53 xaa

-rw-r--r-- 1 root root 100 10月 27 07:53 xab

-rw-r--r-- 1 root root 100 10月 27 07:53 xac

-rw-r--r-- 1 root root 100 10月 27 07:53 xad

-rw-r--r-- 1 root root 100 10月 27 07:53 xae

-rw-r--r-- 1 root root 100 10月 27 07:53 xaf

-rw-r--r-- 1 root root 100 10月 27 07:53 xag

-rw-r--r-- 1 root root 100 10月 27 07:53 xah

-rw-r--r-- 1 root root 100 10月 27 07:53 xai

-rw-r--r-- 1 root root 100 10月 27 07:53 xaj

-rw-r--r-- 1 root root  28 10月 27 07:53 xak

[root@abinlinux ~]# split -b 100 anaconda-ks.cfg  new_      更改名字  new

[root@abinlinux ~]# ls

12                      link    new_ai   xaf

12.tar                  m.txt   new_aj   xag

1.txt                   new_aa  new_ak   xah

2.txt                   new_ab  wps      xai

anaconda-ks.cfg         new_ac  wps.zip  xaj


&&  并且  ||或者

[root@abinlinux ~]# ls 1.txt && ls 2.txt         能够执行第一个才会执行第二个

1.txt

2.txt

[root@abinlinux ~]# ls 1.txt && ls 20.txt     前面的命令执行成功才会执行后面的命令

1.txt

ls: 无法访问20.txt: 没有那个文件或目录

[root@abinlinux ~]# ls 10.txt && ls 2.txt    如果前面的命令没有执行成功 它不再执行后面的命令

ls: 无法访问10.txt: 没有那个文件或目录

[root@abinlinux ~]# ls 1.txt || ls 2.txt

1.txt

[root@abinlinux ~]# ls 10.txt || ls 20.txt

ls: 无法访问10.txt: 没有那个文件或目录

ls: 无法访问20.txt: 没有那个文件或目录

[root@abinlinux ~]# ls 10.txt || ls 2.txt

ls: 无法访问10.txt: 没有那个文件或目录

2.txt

&& 左边的命令执行成功后,才会执行右边的命令

||左边的命令执行不成功,才会执行右边的命令

;   左边的命令成功与否,后面命令都会执行


本文出自 “11325852” 博客,请务必保留此出处http://11335852.blog.51cto.com/11325852/1982959

shell特殊符号,wc,uniq,tee_tr_split命令

标签:shell特殊符号   uniq   wc   tee_tr_split命令   

原文地址:http://11335852.blog.51cto.com/11325852/1982959

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!