When I try to search for a file using the command :
find . -name $tar_file_name -type f -print0|xargs -0
it gives me those errors :
find: ‘./proc/12049’: No such file or directory
find: ‘./proc/20958’: No such file or directory
find: ‘./proc/21062’: No such file or directory
find: ‘./proc/21073’: No such file or directory
Could anyone tell me the reason and possible solutions to solve this ?
If you man find, you could find the below option -ignore_readdir_race.
-ignore_readdir_race
Normally, find will emit an error message when it
fails to stat a file. If you give this option and a
file is deleted between the time find reads the name
of the file from the directory and the time it tries
to stat the file, no error message will be issued.
This also applies to files or directories whose names
are given on the command line. This option takes
effect at the time the command line is read, which
means that you cannot search one part of the filesys-
tem with this option on and part of it with this
option off (if you need to do that, you will need to
issue two find commands instead, one with the option
and one without it).
It will be the best practice to solve this problem.
/proc contains the pids information in files so once a processes's work is done it's pid file will be removed from there. Take it as this way when find ran then /proc/some_pid was present and it has taken in it's memory but when output reached out to xargs as standard input at that time those files were removed since processes would have completed so it is giving an error there since it is not able to find it in system. To remove errors from screen you could do following then.
find . -name "$tar_file_name" -type f -print0 2>/dev/null |xargs -0
Or if you DO NOT want to remove all errors(which above command does) then better ignore /proc path itself from find command then.
find . ! -path '/proc' -name "$tar_file_name" -type f -print0 |xargs -0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With