LinuxQuestions.org
Help answer threads with 0 replies.
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-14-2007, 09:42 PM   #1
koolme
LQ Newbie
 
Registered: Sep 2007
Posts: 1

Rep: Reputation: 0
Smile TAR Multiple Directories


Hi,

I think this maybe easy to answer or maybe not. I want to TAR multiple directories (their files and subdirectories) in which the output of all TAR will be the same as the directory (1 -> 1.tar.gz, 2 -> 2.tar.gz, 3 -> 3.tar.gz ........).

Can this be done? I know cPanel cpbackup script does this but I am doing this on a different server with no cPanel installed. Also, I want to do it that when I extract them, it should be content of the directory already and not the folder and that I need to move the contents (i.e. 1.tar.gz -> 1.htm, 2.htm, 3, 4.pdf and not 2.tar.gz -> 2).

Hope someone can give me the right command.

Thanks!
 
Old 09-14-2007, 09:59 PM   #2
gthill
LQ Newbie
 
Registered: Aug 2007
Posts: 4

Rep: Reputation: 0
It sounds to me like you need a script for doing multiple tars
eg.
cd /home/user/dir1
tar -cvf /home/user/tars/dir1.tar *
cd /home/user/dir2
tar -cvf /home/user/tars/dir2.tar *
cd /home/user/dir3
tar -cvf /home/user/tars/dir3.tar *
 
Old 09-14-2007, 10:03 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,983
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Hi, and welcome to LQ!

Quote:
I think this maybe easy to answer or maybe not. I want to TAR multiple directories (their files and subdirectories) in which the output of all TAR will be the same as the directory (1 -> 1.tar.gz, 2 -> 2.tar.gz, 3 -> 3.tar.gz ........).

Can this be done?
Code:
for i in 1 2 3
do
  cd $i && tar czf ../$i.tar.gz *
done
should do the trick.... no error checking, probably
doesn't fit your needs exactly, but you get the basic
idea - I hope :}


Cheers,
Tink

Last edited by Tinkster; 09-14-2007 at 10:04 PM.
 
  


Reply

Tags
command, multiple, tar


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
Change text in multiple files in multiple directories vivo2341 Linux - General 5 11-27-2006 08:16 PM
Excluding directories from tar? LocoMojo Linux - Software 6 01-24-2006 01:01 AM
Searching multiple directories and sub directories for a file jeep99899 Linux - Newbie 2 10-13-2005 12:23 PM
Help I need help tarring multiple files in multiple directories VisionZ Linux - Newbie 28 03-25-2004 05:25 PM
tar multiple directories computera Linux - General 2 11-17-2001 07:27 AM


All times are GMT -5. The time now is 11:45 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration