ls -lhR /etc/ | egrep *.conf$ >/home/student/total_size.txt 2>/home/student/error.txt
所以我使用这个命令从/etc/
获取所有.conf 文件。我想要 total_size.txt
中的输出和 error.txt
中的错误。我的输出看起来不错,但错误不会重定向到 error.txt
,它们出现在我的终端中:
ls: cannot open directory '/etc/cups/ssl': Permission denied
我不知道该怎么办;我尝试了 2>>
而不是 2>
但它也不起作用。
最佳答案
发生这种情况是因为 ls
的 stderr
仍然指向终端。您需要将管道包裹在花括号中,并在外部进行重定向。例如:
{ ls -lhR /etc/ | egrep *.conf$; } >/home/student/total_size.txt 2>/home/student/error.txt
关于linux - 无法使用 Bash 重定向管道中的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58997776/