A
A
Anatoly2019-01-16 07:16:07
bash
Anatoly, 2019-01-16 07:16:07

Why does find say file/directory not found when it finds it?

Tell me why when you run the command:

find /var/www/ -type d -name modified -exec rm -rf {} \;

I get the message:
find: '/var/www/test/modified': No such file or directory
Although the directory finds and deletes.
I hide the message 2>/dev/nullbut still wonder why? Is he missing something?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jcmvbkbc, 2019-01-16
@Tolly

Is he missing something?

The -prune switch is missing after -exec so that it does not try to go into the newly deleted directory:
find /var/www/ -type d -name modified -exec rm -rf {} \; -prune

S
sergey, 2019-01-21
kuzmin @sergueik

you can also limit yourself to depth 1:

find '/var/www/' -maxdepth 1 -name 'modified' -a -type d -exec rm -f {} \;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question