Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 01-17-2012, 02:49 AM   #1
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


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, 03:04 AM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

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

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

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


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

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

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