LinuxQuestions.org
Register a domain and help support LQ
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 09-20-2009, 04:02 PM   #1
undoIT
Member
 
Registered: Jan 2009
Distribution: Fedora, Ubuntu, Mint, Sabayon
Posts: 35

Rep: Reputation: 15
[SOLVED] Command to Bulk Archive / Compress


I'm looking for a command that will compress every folder within a directory separately with the name of each archive reflecting the original folder name. I know that

tar czvf example.tar.gz example/

will compress an entire folder. However, I have not found a command to bulk archive. Is there such a command?

Last edited by undoIT; 09-21-2009 at 05:39 PM. Reason: solved
 
Old 09-20-2009, 04:47 PM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
for f in *; do tar czvf $f.tar.gz $f; done

-- Well, this assumes you want to tar everything in the directory without exception, but that was the idea I got from your post.

Last edited by slakmagik; 09-20-2009 at 04:48 PM. Reason: second thought
 
Old 09-20-2009, 04:53 PM   #3
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
I guess that this command will do what you want, if I understood you well.

Code:
find . -maxdepth 1 -type d | while read dir; do if [ ! "$dir" == ".." ] && [ ! "$dir" == "." ]; then echo tar czpf "$dir" "$dir".tar.gz; fi; done
 
Old 09-21-2009, 05:37 PM   #4
undoIT
Member
 
Registered: Jan 2009
Distribution: Fedora, Ubuntu, Mint, Sabayon
Posts: 35

Original Poster
Rep: Reputation: 15
Thanks, I ended up using this command to increase the compression by using bzip2:

Code:
find -mindepth 1 -maxdepth 1 -type d -exec tar cjf {}.tar.bz2 {} \;
 
Old 09-21-2009, 05:45 PM   #5
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Quote '{}' unless you are 100% sure that there's no file containing blanks, tabs or line feed on their name, cause all these three characters are default separators for bash, and they CAN appear in file names on Linux. Anyway, there's no reason not to quote them, just to be safe.

Also, if you feel bzip2 is slow, you might want to try lzma or 7z.
 
Old 09-21-2009, 05:49 PM   #6
undoIT
Member
 
Registered: Jan 2009
Distribution: Fedora, Ubuntu, Mint, Sabayon
Posts: 35

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by i92guboj View Post
Quote '{}' unless you are 100% sure that there's no file containing blanks, tabs or line feed on their name, cause all these three characters are default separators for bash, and they CAN appear in file names on Linux. Anyway, there's no reason not to quote them, just to be safe.

Also, if you feel bzip2 is slow, you might want to try lzma or 7z.
Thanks for the heads up. It is doubtful that those characters are in the file name, but never hurts to be on the safe side. I have adjusted the command snippet I have saved on my machine.
 
  


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
[SOLVED] How do I change ca.archive.ubuntu.com to ca2.archive.ubuntu.com at the command line kennymw Linux - Newbie 3 09-01-2009 03:52 AM
compress command does not work sky rulz Linux - Newbie 2 08-18-2009 01:03 AM
shell command for bulk 'rename' ashrafulkarim Linux - Newbie 5 12-17-2008 04:46 AM
What is the Suse 10 command to compress files? rust8y SUSE / openSUSE 5 05-09-2006 07:45 AM
lp command with compress mode zita Linux - General 2 10-06-2005 01:36 PM


All times are GMT -5. The time now is 07:52 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration