BASH - GREP - 反转很多不起作用

时间:2013-03-06 12:44:53

标签: bash grep

我正在尝试通过用户“apache”找到许多打开的文件描述符。我想排除ls: /proc/PID/fd: No such file or directory,但GREP排除不起作用:

# for pid in $(lsof -u apache | awk '{ print $2 }' | uniq); do ls -1 /proc/$pid/fd | grep -v "No"; done | wc -l 
ls: /proc/PID/fd: No such file or directory
1944

2 个答案:

答案 0 :(得分:4)

尝试|& grep -v "No such file or directory"

|不同,|&也会重定向ls的错误输出

答案 1 :(得分:1)

尝试:

for pid in $(lsof -u apache | tail -n +2 | awk '{ print $2 }' | uniq); do ls -1 /proc/$pid/fd ; done | wc -l