0

I want to delete all directories under my home dir but this strange doubt popped in. Will it delete my home dir as well by any chance ? Currently i am using the below oneliner.

find /home/chidori/ -maxdepth 1 -type d -mtime +5 -exec rm -rf {} \;

I was browsing through this forum and i came across this Shell script to delete directories older than n days . The last comment says that it will delete the path mentioned in the command line as well and it urges one to use -mindepth 1 as well.

I would like to if thats true My requirement is to delete the files under /home/chidori/ and not my home dir ( /home/chidori/) itself?

Community
  • 1
  • 1
chidori
  • 1,052
  • 3
  • 12
  • 25

1 Answers1

1

If you want to delete only subdirs under specified path use:

find /home/chidori/ -maxdepth 1 -mindepth 1 -type d -mtime +5 -exec rm -rf {} \;

For test purpose you can echo directories that will be deleted:

find /home/chidori/ -maxdepth 1 -mindepth 1 -type d -mtime +5 -exec echo {} \;
Alexander Yancharuk
  • 13,817
  • 5
  • 55
  • 55