歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux的腳本Bash中find和grep

Linux的腳本Bash中find和grep

日期:2017/2/28 16:23:28   编辑:Linux教程

Linux的腳本Bash中find和grep功能很強大,一個是對目錄文件通過名字和文件屬性來確定所需尋找的文件,列為一個是對文件的內容來匹配尋找文件內的信息。功能相對來說比較單一些,兩者組合起來用,是很強勁的。

--------------------------------------------------------------------------
find . -name -type ... -print
find / -name -type ... -print

*find . -name "*.c" -print
*find /opt ! -type d -print
*find /opt -name "/opt/sch" -prune -o -print
*find . -name "*.c" -print | xarg grep "device"

--------------------------------------------------------------------------

grep -v "abc\>" file
cihlnsv

grep -c 'abc*' file
grep -s 'abc\{2, 4\}def' file

--------------------------------------------------------------------------

在當前但不包括.svn目錄下面查找包含device開頭,並包含flash一或兩次的文件,並顯示詳細列表。
*find . -name "\.svn" -prune | xarg grep -E ‘^device*flash/{1,4/}'

Copyright © Linux教程網 All Rights Reserved