Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to search within my /home/user for a specific folder name and delete it and all its contents. There is a posibility that we would find multiple occurences of the same folder across many folders within /home/user

How do I go about this: Note: Using PuTTY.

share|improve this question

migrated from Dec 4 '11 at 22:55

This question came from our site for professional and enthusiast programmers.

up vote 6 down vote accepted

Try it like this:

find /home/user -type d -iname "searchdir" -exec rm -ir "{}" \;

The find will search /home/user for all directories containing searchdir and execute rm -ir for all of them. It will prompt you for every directory whether it should remove it or not (the -i after rm does that).

Oh...and you might want to add -d 1 to find if it should only search in the upmost hierarchy level.

share|improve this answer

The command to find the folder with certain name is :-

find -type d -name "YOUR_NAME" -print0 | xargs -r0 rm -rf

The above command can avoid argument list too long :- how much should I worry about argument list too long?

Lastly, if you have non-root user access, you likely getting permission denied

share|improve this answer

use the command "find", search for a tutorial on it. a very powerful tool you should know.

share|improve this answer
Could you provide an explanation on how to use it? – Simon Sheehan Dec 5 '11 at 0:30

Well, using

find /home/user -name 'dir_name' -type d

will bring all directories matching dir_name. So you can use xargs and delete it recursively.

find /home/user -name 'dir_name' -type d | xargs rm -r

But, before running above command, check if find command returns all results properly. If you allows me a tip: instead of using rm -r, use mv and move your files to another folder, so nothing will be lost if problems occurs.

share|improve this answer

You must log in to answer this question.