I know a command to do the same with files, but what about folders (and all the files in it of course)?
Asked
Active
Viewed 9,719 times
3 Answers
3
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.
enzotib
- 92,255
- 11
- 164
- 178
-
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
-
1Solved using: rm -rf "/target/directory with spaces/"* – nLinked Dec 10 '11 at 20:12
0
Think that’s not realy true, because if you change or create a file in this folder before you try to remove it, it will not be removed. Because mtime is the modification time and the modification will be done at this time you create or change a file in this directory. Afaik but let me know if I’m false at Linux there is no parameter for creation time.
0
find ./dirc/* -mtime +x -type f -delete
./dirc/*: is your directory (Path)-mtime +x: older than x days-type f: only files-delete: no surprise. Remove it to test before like rm
Maulik Patel
- 151
- 2
-
It seems that you missed that the OP explicitly asked for deletion of folders, not files. – Manu CJ Nov 20 '20 at 10:29