Muhammad
Muhammad

Reputation: 631

How to delete files in different directories in linux with a single command

I've a directory structure which looks like this

main
  -in
      infile1.txt
      infile2.txt        
  -out
      outfile1.txt
      outfile2.txt
  -log
      logfile1.txt
      logfile2.txt

how can I delete files in all the sub directories which are 15 days old.

I know I can use following commands, but I want to do it using a single command.

find in/* -mtime +15 -exec rm {} \; 
find out/* -mtime +15 -exec rm {} \; 
find log/* -mtime +15 -exec rm {} \; 

Upvotes: 1

Views: 115

Answers (2)

Pixic
Pixic

Reputation: 1345

There is a Unix/Linux Stack Exchange...where I found this:

https://unix.stackexchange.com/questions/136804/cron-job-to-delete-files-older-than-3-days

Seems similar to what you are looking for.

Upvotes: 1

Paul R
Paul R

Reputation: 212969

find allows multiple starting points, so you can just do this:

find in out log -mtime +15 -exec rm {} \; 

Upvotes: 2

Related Questions