1. 程式人生 > >shell特殊符號,wc,uniq,tee_tr_split命令

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

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命令