Linux zip program's -d -tt option deletes all files from zip archive
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.