I want to find all directories that contain a certain file and then delete those directories. With
find . -name thatcertainfile -execdir pwd \;
I get a list of all the directories I want to delete, but how could I delete all those directories on the fly? Note, that I want to delete the whole directory and not just the file itself, where I could use
find . -name thatcertainfile -exec rm -r {} \;
Best Answer
Try this command:
rm -rf $(find . -name thatcertainfile -execdir pwd \;)
It should say to the
rm -rf
that what it had to remove is the output of your command. For example, if your command's output was/home/guest/Documents
the command I showed would translate onrm -rf /home/guest/Documents
.