How do I delete a folder in old than 30 days?

How do I delete a folder in old than 30 days?

How to Delete Files Older than 30 days in Linux

  1. Delete Files older Than 30 Days. You can use the find command to search all files modified older than X days.
  2. Delete Files with Specific Extension. Instead of deleting all files, you can also add more filters to find command.
  3. Delete Old Directory Recursively.
  4. Conclusion.

How do I delete a folder older than x days Linux?

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.

How do you write a script to delete files older than x days Linux?

3 Answers

  1. ./my_dir your directory (replace with your own)
  2. -mtime +10 older than 10 days.
  3. -type f only files.
  4. -delete no surprise. Remove it to test your find filter before executing the whole command.

How to delete all directories older than 10 days?

So , to delete all the sub-directories under /path/to/basewhich are older than 10 days; find /path/to/base -mindepth 1 -maxdepth 1 -type d -ctime +10 | xargs rm -rf

How to delete folders older than n days in Bash?

In order to prevent this, just use: find /path/to/base/dir/*.– zloynemecJul 5 ’15 at 8:28 11 you can use -maxdepth 1 to ignore contents of the directories– SamSep 27 ’16 at 19:54 8 The more efficient approach can backfire if you have too many folders to delete: stackoverflow.com/questions/11289551/….

Is there a way to delete all folders in StackOverflow?

The more efficient approach can backfire if you have too many folders to delete: stackoverflow.com/questions/11289551/…. For the same reason, in order to avoid deletion of the base folder it’s better to use -mindepth 1(rather than /path/to/folder/*).