LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 04-23-2011, 07:43 AM   #1
GrumpySnail
LQ Newbie
 
Registered: Apr 2011
Posts: 2

Rep: Reputation: 0
Question 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?
 
Old 04-23-2011, 08:07 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 683Reputation: 683Reputation: 683Reputation: 683Reputation: 683Reputation: 683
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.
 
Old 04-23-2011, 08:27 AM   #3
GrumpySnail
LQ Newbie
 
Registered: Apr 2011
Posts: 2

Original Poster
Rep: Reputation: 0
Lightbulb 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
 
Old 04-23-2011, 02:56 PM   #4
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by GrumpySnail View Post
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.
 
Old 04-24-2011, 03:46 PM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 683Reputation: 683Reputation: 683Reputation: 683Reputation: 683Reputation: 683
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to prevent apt from deleting packages in /var/cache/apt/archives ? abc.linux Debian 11 11-07-2009 11:46 AM
Segmenting archives into a variety of smaller archives. ktek Linux - Software 4 09-25-2008 04:47 AM
Extracting multi-part RAR archives? Kixdemp Linux - Software 2 03-22-2006 05:44 PM
extracting files from RAR archives corbis_demon Linux - Newbie 3 03-30-2005 05:25 AM
Self-extracting Archives for Windows? Trey395 Linux - Software 11 02-20-2004 09:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration