LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 01-17-2012, 03:49 AM   #1
eidbadrlt
LQ Newbie
 
Registered: Nov 2011
Posts: 11

Rep: Reputation: Disabled
tar files for multiple directories


hi im using
for file in * ; do tar -cvf $file.tar $file ; done
but the problem is that the tar files contain the directory as a whole. I want only to have the files of each directory inside the tar.

for example directory
/x/a/file1
..../file2
..../file3

/x/b/file1
..../file2
..../file3

i want to have a.tar and b.tar containing file1, file2, and file3

what should i change in the command?
 
Old 01-17-2012, 04:04 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
You will need to run a separate tar command for each directory then. Why do you want a seperate tar file for each directory?

Code:
for dir in */; do
  tar -C "$dir" -czf "${dir}.tar.gz" .
done
This will produce tar bombs. Files will be extracted in the current directory. This is considered bad form.
 
Old 01-17-2012, 04:54 AM   #3
eidbadrlt
LQ Newbie
 
Registered: Nov 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
I've just solved it with perl!
thanx anyway
 
  


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] tar multiple directories into one file davedpss Linux - Newbie 8 05-16-2011 03:21 PM
[SOLVED] command for tar'ing multiple sub-directories into a single tar file blainemiller Linux - Server 3 04-21-2011 03:05 PM
tar multiple files in different directories... visitnag Linux - Desktop 1 04-14-2008 12:02 AM
TAR Multiple Directories koolme Linux - Newbie 2 09-14-2007 11:03 PM
tar multiple directories computera Linux - General 2 11-17-2001 08:27 AM


All times are GMT -5. The time now is 06:39 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