Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I know a command to do the same with files, but what about folders (and all the files in it of course)?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

The command you refer is find I suppose.

You should use the command -exec rm -r {} \; and add the -depth option.

The -r option to rm remove directories with all the content.
The -depth option tell find to elaborate content of folders before the folder itself.

share|improve this answer
    
That's almost perfect, thanks. Is there a way so it doesn't delete the actual folder I'm searching in? So only folders within the folder get deleted? I'm currently doing "find "/home/user/folder/" -mtime +7 -exec rm -r {} \;", but it deleted the folder called "folder" as well if the time matches. I only want subfolders deleted older than 7 days. –  nLinked Dec 10 '11 at 19:24
1  
Solved using: rm -rf "/target/directory with spaces/"* –  nLinked Dec 10 '11 at 20:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.