Gzip the file older than number of days in Linux
Gzip is the utility provided by Operating system linux, unix for gzip the files and reduce the size of the files with compression method or algorithms.
You can use find command with combination of gzip command to compressed the files older than 1o days by providing parameter mtime with find command. The following command uses find and gzip command.
You can scheduled this command in crontab if you need this activity in regular basis.
The following command find the file present at /var/tmp/ having name with .dbg extension and gzip the files older than 10 days.
/usr/bin/find /var/tmp/*.dbg -mtime +10 -exec gzip {} \;
Note: Used the parameter mtime for specify the older no of days.
Pingback: Batch zip files – Zachary Steinert-Threlkeld
When you specify a glob pattern as in “/var/tmp/*.dbg” you make shell do the actual search, expand the pattern and pass all DBG files individually into the find command, which sort of defies the purpose. Instead you should ise something like “-maxdepth 1 -iname ‘*.dbg'”