Gzip the file older than number of days in Linux

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 .ddg 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.

2 thoughts on “Gzip the file older than number of days in Linux

  1. Pingback: Batch zip files – Zachary Steinert-Threlkeld

  2. George

    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'”

    Like

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.