Reputation: 41
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 ?
Upvotes: 3
Views: 13345
Reputation: 101
Prevent traversal of the proc filesystem by using the "prune" action. Note that the "not" (!) operator won't work in this case, as the proc filesystem will still be traversed, leading to the "No such file or directory" errors.
To prevent traversing the proc filesystem when executing the find command, use
-path /proc -prune
Note that when "prune" is the only action in the find command, the command will (perhaps counter-intuitively) show the files that have been pruned instead of ignoring those files.
From the find man page:
If the expression contains no actions other than -prune, -print is performed on all files for which the expression is true.
To prevent this, one should use the "print" action: -path /proc -prune -o -print
The print option has to be added after other options that narrow down the search, for instance -path /proc -prune -o -name file_to_find -o print
. If the "exec" action is being used, for instance, the "print" action is not required.
Upvotes: 2
Reputation: 141
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.
Upvotes: 4
Reputation: 133780
/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
Upvotes: 4