Search code examples
bashshellfindexecrm

Removing all subfolders older than 3 days inside a folder, but keep the main folder


I have a directory structure like this:

news_images folder -> subfolder with current date ex. 20140626 -> files

I would like to remove all subfolders with files inside news_images directory that are older than 3 days.

This does remove only files inside news_images directory but do not touch the subfolders.

find news_images -mtime +3 -exec rm {} \;

Solution

  • rm without options is not able to delete directories. Try option -r.