7、linux的基础命令(4)

1、cut 

       -d: 指定字段分隔符,默认是空格
-f: 指定要显示的字段
-f 1,3
-f 1-3

[root@localhost test2]# cut -d: -f1 /etc/passwd
root
bin
daemon
adm
lp
[root@localhost test2]# cut -d: -f1-2 /etc/passwd
root:x
bin:x
daemon:x
adm:x



2、sort  文本排序,(默认按照ASCII排序)

       -n: 数值排序
 -r: 降序
 -t: 字段分隔符
-k: 以哪个字段为关键字进行排序
        -u: 排序后相同的行只显示一次
-f:: 排序时忽略字符大小写

#默认按照ASCII排序
[root@localhost test2]# cut -d: -f1-2 /etc/passwd | sort 
abrt:x
adm:x
apache:x
avahi-autoipd:x
bin:x
daemon:x
dbus:x

#指定按照,整数的排序规则来排序
[root@localhost test2]# cut -d: -f1,3 /etc/passwd | sort -n -t: -k 2
root:0
bin:1
daemon:2
adm:3
lp:4
sync:5
shutdown:6

#-r 降序排列
[root@localhost test2]# cut -d: -f1,3 /etc/passwd | sort -n -t: -k 2 -r
user1:501
zhangbaowei:500
rtkit:499
pulse:498
saslauth:497
abrt:173
avahi-autoipd:170
usbmuxd:113
nobody:99



3、wc  ( world count ) 文本统计

         -l    行数
-w   单词数
-c    字节数

[root@localhost test2]# wc /etc/passwd
  32   46 1488 /etc/passwd

#统计行数    -l
[root@localhost test2]# wc  -l /etc/passwd
32 /etc/passwd
#统计单词数  -w
[root@localhost test2]# wc -w /etc/passwd
46 /etc/passwd
#统计字节数  -c
[root@localhost test2]# wc -c /etc/passwd
1488 /etc/passwd


4、tr    -translate or delete characters

          tr [OPTION]... SET1 [SET2]
            -d: 删除出现在字符集中的所有字符

      

#字符大写的转换
[root@localhost test2]# cut -d: -f1-2 /etc/passwd 
root:x
bin:x
daemon:x
adm:x
lp:x
sync:x
shutdown:x

[root@localhost test2]# cut -d: -f1-2 /etc/passwd | tr  'a-z' 'A-Z'
ROOT:X
BIN:X
DAEMON:X
ADM:X
LP:X
SYNC:X

#字符的删除
[root@localhost test2]# cut -d: -f1-2 /etc/passwd 
root:x
bin:x
daemon:x

[root@localhost test2]# cut -d: -f1-2 /etc/passwd | tr -d 'x'
root:
bin:
daemon:



你可能感兴趣的:(sort,tr,wc,cut,linux的基础命令)