我正在尝试通过用户“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
答案 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