Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find - suppress "No such file or directory" errors

Tags:

find

bash

unix

I can use -s in grep to suppress errors, but I don't see an equivalent for the find command in the man page... Is the only option to redirect STDERR>/dev/null?

Or is there an option that handles this? (open to fancy awk and perl solutions if needed)

Example:

$ for dir in `ls /mnt/16_c/`; do find /mnt/16_c/$dir/data/ -mtime +180 -type f -exec echo {} \;; done
find: `/mnt/16_c/test_container/dat/': No such file or directory
like image 517
JacobIRR Avatar asked Aug 08 '17 17:08

JacobIRR


1 Answers

You can redirect stderr with 2>/dev/null, for example:

find /mnt/16_c/$dir/data/ -mtime +180 -type f -exec echo {} \; 2>/dev/null

Btw, the code in your question can be replaced with:

find /mnt/16_c/*/data/ -mtime +180 -type f 2>/dev/null

And if there is at least one matching directory, then you don't even need to suppress stderr, because find will only search in directories that match this pattern.

like image 111
janos Avatar answered Sep 19 '22 12:09

janos