Total Pageviews

Saturday, September 13, 2014

find and delete old logfiles or find and compress old logfiles command in linux

below is the command to find and delete old logfiles older than 7 days.
 you need to the same directory to run this command or you can specify at the beginning to CD to that directory and run this command in a shell script.


find . ! -mtime -7 | while read fname
do
if [ -f $fname ]; then
rm $fname
fi
done

find and compress command. compress files older than 3 days

find . ! -mtime -3 |while read fname
do
if [ -f $fname ]; then
gzip $fname
fi
done

No comments:

Post a Comment