Linux shell基础命令(一)

  • cut 

MacBook-Pro:20170405 qiuxuefei$ cat /etc/passwd |tail  -2 

_fpsd:*:265:265:FPS Daemon:/var/db/fpsd:/usr/bin/false

_timed:*:266:266:Time Sync Daemon:/var/db/timed:/usr/bin/false

MacBook-Pro:20170405 qiuxuefei$ cat /etc/passwd |tail  -2 |cut -d ":" -f 1

_fpsd

_timed

MacBook-Pro:20170405 qiuxuefei$ cat /etc/passwd |tail  -2 |cut -d ":" -f 1,2

_fpsd:*

_timed:*

MacBook-Pro:20170405 qiuxuefei$ cat /etc/passwd |tail  -2 |cut -d ":" -f 1-3

_fpsd:*:265

_timed:*:266

MacBook-Pro:20170405 qiuxuefei$ cat /etc/passwd |tail  -2 |cut -c 3

p

i

  • sort

MacBook-Pro:20170405 qiuxuefei$ cat tail_passwd.log 

_findmydevice:*:254:254:Find My Device Daemon:/var/db/findmydevice:/usr/bin/false

_datadetectors:*:257:257:DataDetectors:/var/db/datadetectors:/usr/bin/false

_captiveagent:*:258:258:captiveagent:/var/empty:/usr/bin/false

_ctkd:*:259:259:ctkd Account:/var/empty:/usr/bin/false

_applepay:*:260:260:applepay Account:/var/db/applepay:/usr/bin/false

_hidd:*:261:261:HID Service User:/var/db/hidd:/usr/bin/false

_cmiodalassistants:*:262:262:CoreMedia IO Assistants User:/var/db/cmiodalassistants:/usr/bin/false

_analyticsd:*:263:263:Analytics Daemon:/var/db/analyticsd:/usr/bin/false

_fpsd:*:265:265:FPS Daemon:/var/db/fpsd:/usr/bin/false

_timed:*:266:266:Time Sync Daemon:/var/db/timed:/usr/bin/false

@

*

^

<

>

1112

1212

afasfasfasfa

444232

 

MacBook-Pro:20170405 qiuxuefei$ sort tail_passwd.log 

 

*

1112

1212

444232

<

>

@

^

_analyticsd:*:263:263:Analytics Daemon:/var/db/analyticsd:/usr/bin/false

_applepay:*:260:260:applepay Account:/var/db/applepay:/usr/bin/false

_captiveagent:*:258:258:captiveagent:/var/empty:/usr/bin/false

_cmiodalassistants:*:262:262:CoreMedia IO Assistants User:/var/db/cmiodalassistants:/usr/bin/false

_ctkd:*:259:259:ctkd Account:/var/empty:/usr/bin/false

_datadetectors:*:257:257:DataDetectors:/var/db/datadetectors:/usr/bin/false

_findmydevice:*:254:254:Find My Device Daemon:/var/db/findmydevice:/usr/bin/false

_fpsd:*:265:265:FPS Daemon:/var/db/fpsd:/usr/bin/false

_hidd:*:261:261:HID Service User:/var/db/hidd:/usr/bin/false

_timed:*:266:266:Time Sync Daemon:/var/db/timed:/usr/bin/false

afasfasfasfa

MacBook-Pro:20170405 qiuxuefei$ sort -n tail_passwd.log 

 

*

<

>

@

^

_analyticsd:*:263:263:Analytics Daemon:/var/db/analyticsd:/usr/bin/false

_applepay:*:260:260:applepay Account:/var/db/applepay:/usr/bin/false

_captiveagent:*:258:258:captiveagent:/var/empty:/usr/bin/false

_cmiodalassistants:*:262:262:CoreMedia IO Assistants User:/var/db/cmiodalassistants:/usr/bin/false

_ctkd:*:259:259:ctkd Account:/var/empty:/usr/bin/false

_datadetectors:*:257:257:DataDetectors:/var/db/datadetectors:/usr/bin/false

_findmydevice:*:254:254:Find My Device Daemon:/var/db/findmydevice:/usr/bin/false

_fpsd:*:265:265:FPS Daemon:/var/db/fpsd:/usr/bin/false

_hidd:*:261:261:HID Service User:/var/db/hidd:/usr/bin/false

_timed:*:266:266:Time Sync Daemon:/var/db/timed:/usr/bin/false

afasfasfasfa

1112

1212

444232

MacBook-Pro:20170405 qiuxuefei$ sort -nr tail_passwd.log 

444232

1212

1112

afasfasfasfa

_timed:*:266:266:Time Sync Daemon:/var/db/timed:/usr/bin/false

_hidd:*:261:261:HID Service User:/var/db/hidd:/usr/bin/false

_fpsd:*:265:265:FPS Daemon:/var/db/fpsd:/usr/bin/false

_findmydevice:*:254:254:Find My Device Daemon:/var/db/findmydevice:/usr/bin/false

_datadetectors:*:257:257:DataDetectors:/var/db/datadetectors:/usr/bin/false

_ctkd:*:259:259:ctkd Account:/var/empty:/usr/bin/false

_cmiodalassistants:*:262:262:CoreMedia IO Assistants User:/var/db/cmiodalassistants:/usr/bin/false

_captiveagent:*:258:258:captiveagent:/var/empty:/usr/bin/false

_applepay:*:260:260:applepay Account:/var/db/applepay:/usr/bin/false

_analyticsd:*:263:263:Analytics Daemon:/var/db/analyticsd:/usr/bin/false

^

@

>

<

*

 

  • wc 

 

MacBook-Pro:20170405 qiuxuefei$ cat  wc.log

aaa

bbb

1233

MacBook-Pro:20170405 qiuxuefei$ wc -l wc.log 【行数】

       3 wc.log

MacBook-Pro:20170405 qiuxuefei$ wc -m wc.log 【字符数,包含换行符】

      13 wc.log

MacBook-Pro:20170405 qiuxuefei$ wc -w wc.log  【单词数】

       3 wc.log

  • uniq

MacBook-Pro:20170405 qiuxuefei$ cat 2.text 

qq

wqwq

1

2

1

MacBook-Pro:20170405 qiuxuefei$ uniq 2.text 

qq

wqwq

1

2

1

MacBook-Pro:20170405 qiuxuefei$ cat 3.text 

qq

wqwq

1

1

2

MacBook-Pro:20170405 qiuxuefei$ uniq 3.text 

qq

wqwq

1

2

 

MacBook-Pro:20170405 qiuxuefei$ cat 2.text 

qq

wqwq

1

2

1

qq

qw

qq

2

3

2

MacBook-Pro:20170405 qiuxuefei$ uniq -c 2.text 

   1 qq

   1 wqwq

   1 1

   1 2

   1 1

   1 qq

   1 qw

   1 qq

   1 2

   1 3

   1 2

MacBook-Pro:20170405 qiuxuefei$ sort 2.text |uniq -c

   2 1

   3 2

   1 3

   3 qq

   1 qw

   1 wqwq

 

  • tee 

sort 2.text |uniq -c tee tee.log 【输出+重定向】

sort 2.text |uniq -c tee  -a. tee.log 【输出+追加重定向】

  • tr

MacBook-Pro:20170405 qiuxuefei$ sort 2.text |uniq -c  | tr 'q' 'Q'

   2 1

   3 2

   1 3

   3 QQ

   1 Qw

   1 wQwQ

MacBook-Pro:20170405 qiuxuefei$ sort 2.text |uniq -c  | tr '[a-z]' '[A-Z]'

   2 1

   3 2

   1 3

   3 QQ

   1 QW

   1 WQWQ

  • split 

split  -l  【按照行切割】

​​​​​​​split  -b  100  aaa.text 【按照大小切割】

转载于:https://my.oschina.net/u/3771523/blog/1632414

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值