Linux中常用查找命令.md

2019-05-21  本文已影响0人  回忆的时间沙漏

目前用的两个比较方便的查找命令

find

选项

find .
find /home -name "*.txt"
find /home -iname "*.txt"
find . \( -name "*.txt" -o -name "*.pdf" \)

或

find . -name "*.txt" -o -name "*.pdf" 
find /home ! -name "*.txt"
find /usr/ -path "*local*"

grep

选项

#ps -ef | grep  -c python
5
#ps -ef | grep -n python
289:root       3266      1  0 May20 ?        00:00:51 /usr/bin/python -Es /usr/sbin/tuned -l -P
295:root       3470      1  0 May20 ?        00:01:05 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf
624:root      49455  49423  0 16:13 ?        00:00:00 python main.py mxvote show
626:root      49560 100819  0 16:13 pts/2    00:00:00 grep --color=auto -n python
721:root     108367 107290  7 15:02 pts/6    00:05:16 /usr/bin/python /bin/dstat -l -m -r -c --top-io --top-mem --top-cpu

规则表达式

cat test.txt | grep -E "^ben"     # 匹配test.txt中以ben开始的行
cat test.txt | grep -E "ben$"   匹配test.txt中以ben结尾的行
  - cat test.txt | grep -E "9[^0]"   匹配test.txt中不是90的信息,但是会匹配91,92
  - cat test.txt | grep -E "grep '^[^#]'  files   匹配test.txt中行首不为#的行作为输出
  - '*grep'匹配所有一个或多个空格后紧跟grep的行

上一篇 下一篇

猜你喜欢

热点阅读