運行該find命令時,可能會輸出“No such file or directory”錯誤。
正如對find - suppress "No such file or directory" 錯誤問題的回答:https ://stackoverflow.com/a/45575053/7939871 ,將檔案描述符 2 重定向到/dev/null將愉快地消除來自 的錯誤訊息find,例如No such file or directory:
find yada-yada... 2>/dev/null
這完全沒問題,只要不-exec用于執行命令。因為2>/dev/null也會使執行命令中的錯誤靜音。
舉個例子:
$ find /root -exec sh -c 'echo "Error" >&2' {} \; 2>/dev/null
$ find /root -exec sh -c 'echo "Error" >&2' {} \;
Error
find: ‘/root’: Permission denied
有沒有辦法find在保留執行命令的錯誤的同時消除錯誤?
uj5u.com熱心網友回復:
在命令中使用-exec選項find是將命令集成xargs到find命令中。
find您始終可以-exec通過管道將find輸出與xargs命令分開。
例如:
find / -type f -name "*.yaml" -print0 2>/dev/null | xargs ls -l
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/468664.html
