bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #42985] find reports "No such file or directory" when executing rm


From: Bernhard Voelker
Subject: [bug #42985] find reports "No such file or directory" when executing rm
Date: Thu, 21 Sep 2017 02:47:32 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0

Follow-up Comment #4, bug #42985 (project findutils):

Well, this is the result of the order of processing in 'find'
disturbed by the deletion action of 'rm'.

First, let's see what find would call in which order if 'rm'
would not get in its way by putting 'echo' in front of 'rm':

 0  $ find $(pwd) . -mindepth 1 -exec echo rm -rf '{}' \;
 1  rm -rf /home/a/findtest/1
 2  rm -rf /home/a/findtest/1/b
 3  rm -rf /home/a/findtest/1/a
 4  rm -rf /home/a/findtest/2
 5  rm -rf /home/a/findtest/2/b
 6  rm -rf /home/a/findtest/2/a
 7  rm -rf ./1
 8  rm -rf ./1/b
 9  rm -rf ./1/a
10  rm -rf ./2
11  rm -rf ./2/b
12  rm -rf ./2/a

Already with command on line 1 'rm' would remove the directory '1'.
Then, 'find' would continues to search for the content of '1' (from
which it knows that it is a directory from before), but that does
not exist anymore. That's why find complains about that in your example.
The same applies to the directory '2'.

For what it's worth, find does not complain about anything below the
2nd command line argument "." because at the time find starts processing
that argument, there is no content which would match '-mindepth 1'.

The following is similar to your command but uses
* a -printf action before the -exec option to see what command it would call,
* and with 'rm -v' to see what file is actually deleted at which time,
thus proving the above explanation:

  0  $ find $(pwd) . -mindepth 1 -printf "debug: call rm for '%p'\n" -exec rm
-rv '{}' \;
  1  debug: call rm for '/home/a/findtest/1'
  2  removed ‘/home/a/findtest/1/b’
  3  removed ‘/home/a/findtest/1/a’
  4  removed directory: ‘/home/a/findtest/1’
  5  find: ‘/home/a/findtest/1’: No such file or directory
  6  debug: call rm for '/home/a/findtest/2'
  7  removed ‘/home/a/findtest/2/b’
  8  removed ‘/home/a/findtest/2/a’
  9  removed directory: ‘/home/a/findtest/2’
 10  find: ‘/home/a/findtest/2’: No such file or directory

The lines 2-4 are the output of the first rm command incovation
for the directory '/home/a/findtest/1' as stated in line 1.
In line 5, find complains about the same directory not there
any more.

What you probably want is using a depth-first processing,
i.e., the '-depth' option:

  $ find $(pwd) . -mindepth 1 -depth -printf "debug: call rm for '%p'\n" -exec
rm -rv '{}' \;
  debug: call rm for '/home/a/findtest/1/b'
  removed ‘/home/a/findtest/1/b’
  debug: call rm for '/home/a/findtest/1/a'
  removed ‘/home/a/findtest/1/a’
  debug: call rm for '/home/a/findtest/1'
  removed directory: ‘/home/a/findtest/1’
  debug: call rm for '/home/a/findtest/2/b'
  removed ‘/home/a/findtest/2/b’
  debug: call rm for '/home/a/findtest/2/a'
  removed ‘/home/a/findtest/2/a’
  debug: call rm for '/home/a/findtest/2'
  removed directory: ‘/home/a/findtest/2’

Thus said, I think this is all expected behaviour.

BTW: creating one 'rm' process per file is not very elegant, and
even unnecessary with 'rm -r' as that operates recursively.
This would create only one process per file found in the current
directory, and leave the recursive processing up to 'rm':

  $ find $(pwd) -mindepth 1 -maxdepth 1 -exec rm -rv '{}' \;

... or even use "find ... -exec ... +" to have as many 'rm' processes
as necessary, maybe only one.

Have a nice day,
Berny


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?42985>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]