ram
ram

Reputation: 21

Unix shell script to delete older log files

Could someone please give me the command to delete log files before today (except today and yesterday) date?

Upvotes: 2

Views: 5533

Answers (2)

Shamit Verma
Shamit Verma

Reputation: 3827

find /path/to/files* -mtime +2 -delete

Upvotes: 0

paxdiablo
paxdiablo

Reputation: 881323

You can use find with the -mtime option to get a list of files modified more than N days ago.

For example:

find . -maxdepth 1 -name '*.txt' -mtime +2

will give you all the *.txt files in the current directory older than 48 hours.

You can add -delete to actually get rid of them.

Upvotes: 3

Related Questions