Linux的脚本Bash中find和grep


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/}'

相关内容