3

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

nLinked
  • 3,387

3 Answers3

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
  • 96,093
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

Auto delete files older than 7 days