LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Linux zip program's -d -tt option deletes all files from zip archive (http://www.linuxquestions.org/questions/linux-software-2/linux-zip-programs-d-tt-option-deletes-all-files-from-zip-archive-877048/)

Arun Gupta 04-25-2011 08:22 PM

Linux zip program's -d -tt option deletes all files from zip archive
 
I have recently started working with Linux server (Oracle Enterprise Linux 5.5 which is same as Red Hat Linux 5.5). I have worked on Linux but not extensively. Whenever I run into a problem, Google search always finds me more that one right answers on this forum. Today I decided to register and post a question to which I could not find any answer.

Here is my problem.

I am using Linux zip utility to zip the logs into a zipped archive, say logs.zip. To delete logs older than 30 days from the zip file, I wanted to use the -d -tt options but these are not working as I expected.

My understanding of -d and -tt option is that -d will delete files from archive and -tt mmddyyyy will delete only files older than a certain date. However, when I use the -d -tt mmddyyyy options, all files are deleted from the archive irrespective of the file modification date.


-d
Remove (delete) entries from a zip archive.

-tt mmddyyyy
Do not operate on files modified after or at the specified date, where mm is the month (0-12), dd is the day of the month (1-31), and yyyy is the year. The ISO 8601 date format yyyy-mm-dd is also accepted.

Please let me know if my understanding of the -tt option is incorrect. If -tt option does not work the way I expected it, how else can I achieve my objective without resorting to unzip/delete/zip again process?

Thanks in advance for the help.

gentisle 04-25-2011 10:52 PM

I'm not a zip expert, however, from reading the help printed from zip, it looks like you are pitting one zip option against the other. The -d does delete, but the -tt is for including into an archive you are creating. So it sounds like the -d option "overrides" the -tt option.

Code:

Date filtering:
  -t date  exclude before (include files modified on this date and later)
  -tt date  include before (include files modified before date)
  Can use both at same time to set a date range
  Dates are mmddyyyy or yyyy-mm-dd

I think you need to write a script that deletes based on your date specs.

Arun Gupta 04-26-2011 07:21 PM

I have modified scripts to use rar instead of zip. It can do date/duration based deletes. Thanks...

gentisle 04-26-2011 08:48 PM

BTW, have you tried 7-zip for archiving? My tests show that it compresses better, but I haven't tried rar.

Arun Gupta 04-27-2011 08:06 PM

I use 7-zip on Windows desktop. Never used it on Linux. The problem is that I am not permitted to use any freeware on the Linux servers without going through a complicated maze of obtaining permissions from security team.

We already have licenses for rar since I have been using it on Windows servers for last 5 years. The rar archive can be opened using WinZip. I am not sure about the 7z format. Sometimes I have to send the archive files to third parties.

In terms of program options, I can safely say that rar is the more feature rich than 7-zip or zip. I have converted my script to use rar instead of zip and it worked as expected.

Thanks...


All times are GMT -5. The time now is 09:14 PM.