我想做一个递归的grep。所以我通常会做以下事情:
grep pattern -r /some/path
通常这会起作用。但是,当FIFO文件驻留在路径中时,grep会卡在那里。
johnson@ISD32_54_sles10:~/tmp$ ls -l 1
prw-r--r-- 1 neoli users 0 2012-05-16 17:24 1
然后我调用strace命令来识别问题,我得到了这个。
...
stat64("./1", {st_mode=S_IFIFO|0644, st_size=0, ...}) = 0
open("./1", O_RDONLY|O_LARGEFILE) = 3
read(3, <unfinished ...>
所以我的问题是当路径中有FIFO时如何进行递归grep? grep是否有一个命令行选项,它会告诉grep在指定时忽略FIFO?
感谢您的帮助。
答案 0 :(得分:6)
来自man grep
(GNU)
-D ACTION, --devices=ACTION
If an input file is a device, FIFO or socket, use ACTION to process it.
By default, ACTION is read, which means that devices are read just as if
they were ordinary files. If ACTION is skip, devices are silently skipped.
答案 1 :(得分:2)
一种方法是使用find
find . -type f -exec grep pattern {} \;
这只会对常规文件上的模式进行grep(所以没有符号链接,管道等)