LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   extracting and then deleting archives? (https://www.linuxquestions.org/questions/linux-newbie-8/extracting-and-then-deleting-archives-876652/)

GrumpySnail 04-23-2011 07:43 AM

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?

jschiwal 04-23-2011 08:07 AM

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.

GrumpySnail 04-23-2011 08:27 AM

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

MTK358 04-23-2011 02:56 PM

Quote:

Originally Posted by GrumpySnail (Post 4333571)
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.

jschiwal 04-24-2011 03:46 PM

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.


All times are GMT -5. The time now is 02:25 PM.