Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
04-23-2011, 07:43 AM
|
#1
|
LQ Newbie
Registered: Apr 2011
Posts: 2
Rep:
|
extracting and then deleting archives?
I have a large number of zip-archives which I would like to extract and then delete, keeping only the extracted files. The files are located in a number of directories and I issued the following command, hoping that it would solve my problem (which it didn't):
Code:
find . -name "*.zip" -execdir unzip '{}' \; -delete
What happened was that find continued to extract the files as intended, but then it deleted not only the zip-archives but also the newly extracted files. Thankfully it only affected a portion of the files that I had already backed up.
I don't have enough space on my hard drive to extract all the files without simultaneously removing any data and I don't have the energy to go through all the directories one by one manually. Surely there must be a better way. Is there a way to fix the code snippet above so that it works as I intended or is there a better way of doing this?
|
|
|
04-23-2011, 08:07 AM
|
#2
|
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
I tried out your line in a test directory where I had a couple zip files I created for the test. The command extracted the zip files and deleted the zip files. It worked for me.
Did you have zip files archived inside the zip files?
By the way, for Linux, I'd recommend using tar instead of zip.
Last edited by jschiwal; 04-23-2011 at 08:11 AM.
|
|
|
04-23-2011, 08:27 AM
|
#3
|
LQ Newbie
Registered: Apr 2011
Posts: 2
Original Poster
Rep:
|
thankyou!
Well, I think you have helped me figure out what my problem was, and of course you are absolutely right; the line DID work. The missing files from some of the directories seem to have been caused by omitting the semicolon operand while tinkering with the line. I can't tank you enough for your trouble and I'm a bit embarrassed for posting what turned out to be a non issue, but I don't think I would have figured it out without that being pointed out so rest assured you effort was not in vain.
Thanks for the tip of using tar instead of zip by the way, I'll keep it in mind.
Yours,
VectorLinux Newbie
|
|
|
04-23-2011, 02:56 PM
|
#4
|
LQ 5k Club
Registered: Sep 2009
Posts: 6,443
|
Quote:
Originally Posted by GrumpySnail
Thanks for the tip of using tar instead of zip by the way, I'll keep it in mind.
|
Just remember that tar is purely an archive format, it doesn't do any compression. To compress your tar archives, you have to use a separate compression format such as gzip, bzip2, or xz (they only compress, they do not archive).
And if your issue is solved, mark the thread as solved.
|
|
|
04-24-2011, 03:46 PM
|
#5
|
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
Actually, you can use the -z or -j tar options to compress the files using gzip or bzip2 respectively. If you use compression, you can't insert or delete files from an archive.
Also look at the --listed-incremental option to create incremental backups.
Read section 5.2 in the "info tar" manual for instructions and examples of incremental dumps.
---
It looks like you may be creating zip files of directories and restoring them to the target.
One of my favorite uses of tar is like this:
tar -C <basedirectory> -cf - dir1 dir2 dir3 dir4 dir5 | ssh user@host 'tar -C <target_basedirectory> -xfv -'
This replicates the files onto a target machine. It can be combined with --listed-incremental to create file backups.
Also look at using rsync for replication.
Last edited by jschiwal; 04-24-2011 at 03:50 PM.
|
|
|
All times are GMT -5. The time now is 02:22 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|