Unix deletes all folders in a directory with a specific name

Hi, I have many folders called "@eaDir" on one of my drives, and I would like to find them, find all and delete them and their contents.

I know this is probably a combination of the find and rm command, but I cannot fully understand it. Can anyone help?

+4
source share
3 answers

Try the following:

find . -type d -name '@eaDir' -print0 | xargs -rt0 rm -rv 

Here is the same, but using explicit long options for xargs :

 find . -type d -name '@eaDir' -print0 | xargs --no-run-if-empty --verbose --null rm -rv 

(using long parameters is always a good idea if you write scripts that need to be supported / viewed by other people)

But above all:

 man find man xargs 
+4
source
 find /path/to/the/disk -type d -name "@eaDir" -delete 

Note that the order here is fundamental: quoting manpage,

Warnings. Do not forget that the find command line is evaluated as an expression, so first setting -delete will make find try to delete everything below the starting points you specified.

So, as usual, first try running the find with -print , and then when you check that everything is working fine, replace it with -delete . Note that -delete means -depth , so to conduct meaningful testing with -print you must explicitly specify it in the expression:

When testing the find command line that you later intend to use with -delete, you must explicitly specify -depth to avoid later surprises.

+1
source

Open the root folder or directory and run the following command:

 find . -path '*/@eaDir/*' -delete -print && find . -path '*/@eaDir' -delete -print 

This should work for you.

0
source

All Articles