Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to zip the files older than today's date? 1

Status
Not open for further replies.

wesbooks

Programmer
Sep 8, 2002
22
CA
I have a directory containing sub-directories and files. How can we locate all the files are older than today's date and zip it? If the file is already zipped, skip the file?
 
find . -type f -mtime +1 -print | grep -v ".zip" | zip zipfile
 
you can create a /tmp/x file with the creation date to be "today 00:00:00", after use it the find command
like:

Code:
[mpreda web]$ touch -t `date +'%m%d'`0000 /tmp/x
[mpreda web]$ ls -l /tmp/x
-rw-rw-r--    1 mpreda   users           0 Jan 19 00:00 /tmp/x
[mpreda web]$ find /path/to/your/dir -newer /tmp/x -type f

___
____
 
find /MyDir -type f -mtime +1|grep -v '.gz'|xargs gzip



----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Hello mrregan,

Thank you very much for your reply. This is what I need. However, I don't know how to plug in the zipfile name. I want the file name to be the origianl file name with zip extension. e.g. abc.log -> abc.log.zip

=======================================
mrregan (MIS) Jan 19, 2005

find . -type f -mtime +1 -print | grep -v ".zip" | zip zipfile
 

Use xargs as in my post.


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
find . -type f -mtime +1 ! -name '*.zip' -exec zip {} \;

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top