Linux: Find and rename files

I’m using smokeping, i see a bunch of files that is no longer needed. To be safe, i want to rename find these files and rename them. I came with this solution

find /var/lib/smokeping/rrd/ -name "*.rrd" -type f  -mtime +30 -exec bash -c 'mv $0 $(echo "$0" | sed -r "s|\.rrd|\.rrd\.old|g")' '{}' \;

The above command will find all files with ext .rrd and not modified in the last 30 days.

Leave a Reply

Your email address will not be published. Required fields are marked *