Qwertyash
Qwertyash

Reputation: 1

How to zip latest created file in unix

I want to zip number of files created on particular day. I used this command

zip -rt 06222012 TEST root/*.csv

this command zipped all the files in root directory with .csv extension created on date >=22/6/2012

But this doesn't meet my requirement. My requirement is.. lets suppose there are two scripts a.sh and b.sh a.sh(Manual run) executes at time 22/6/2012 1:00 AM and completes at 22/6/2012 4:00 AM and creates 4 .csv file

After this b.sh file executes through cron job on 22/6/2012 6:00 AM and completes at 22/6/2012 10:00 AM and creates 5 .csv file

Above zip command will zip all these 9 files as they are created on same day that is 22/6/2012, but I need only 5 .csv files which get created by b.sh only, that means the files which got created on 22/6/2012 10:00 AM

In the above zip command can I also give the hour and minute too ?

Upvotes: 0

Views: 1439

Answers (1)

mikyra
mikyra

Reputation: 10347

Given the fact already mentioned in the comments above that with using a standard filesystem your only chance is to approximate "files created" by "files last modified" you probably might want to adress the problem using find.

There already is a good article about that on stackoverflow (see: Shell Script — Get all files modified after <date>)

Regarding your case most probably the -newerXY option might be the one best fitting to the problem with something like:

  zip -r TEST `find root -name"*.csv" -newermt 10:00`

Upvotes: 1

Related Questions