LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 02-28-2004, 12:15 PM   #1
FransE
LQ Newbie
 
Registered: Feb 2004
Posts: 6

Rep: Reputation: 0
Problem with properly creating a tar archive


Hi all,

In a bash script of mine I create a tar archive from a file which contains
absolute paths to the files the archive should contain(supplied via the
--files-from argument). The lines is of the type /foo/bar/a, /foo/bar/b etc.
- all the specified files is in one folder.
The problem is, when I untar the archive the whole directory structure is
created, foo/bar/ and then the files - I just want all the files in the
toplevel of the archive. Any ideas? Suggestions highly appreciated.

BTW, does anyone know a good mailinglist/forum for tricky hardware questions?
(I don't want to go for LKML)


Cheers,

________________Frans
 
Old 02-28-2004, 12:21 PM   #2
TheOneKEA
Member
 
Registered: Oct 2003
Location: Somewhere in Surrey
Distribution: Debian GNU/Linux 7.4.0 (amd64) w/kernel 3.13.0
Posts: 279

Rep: Reputation: 30
You want a flat tar archive, right - one where the directory structure does not exist?
 
Old 02-28-2004, 12:26 PM   #3
FransE
LQ Newbie
 
Registered: Feb 2004
Posts: 6

Original Poster
Rep: Reputation: 0
Yupp!

Frans
 
Old 02-28-2004, 12:33 PM   #4
TheOneKEA
Member
 
Registered: Oct 2003
Location: Somewhere in Surrey
Distribution: Debian GNU/Linux 7.4.0 (amd64) w/kernel 3.13.0
Posts: 279

Rep: Reputation: 30
What you want doesn't exist - the only workaround is to create the tarball with the -P switch to prevent the stripping of leading '/' characters, and then unnzipping the tarball in the parent directory of the directory structure that you want backed up.
 
Old 02-28-2004, 12:39 PM   #5
FransE
LQ Newbie
 
Registered: Feb 2004
Posts: 6

Original Poster
Rep: Reputation: 0
Ok. But there must be a solution to my problem:

I have N files spread out over the place, and I want to collect them together in the toplevel of the tar file. (and the files are in different places, some are in /foo/bar/ othere's in /foo/foo)

Cheers,
Frans
 
Old 02-28-2004, 04:15 PM   #6
dford
Member
 
Registered: May 2003
Location: Kansas
Distribution: RH 9, OpenBSD, FreeBSD
Posts: 60

Rep: Reputation: 19
There is indeed a way. You will probably have to do some scripting, but it isn't that hard.

Lets start with a file, file.lst, that contains all of the fully qualified file names you want to tar:
Code:
/var/log/dmesg
/usr/bin/firebird
Code:
TARFILE=/backups/backup_$(date +%G%m%d).tar
for i in $(cat file.lst)
do
   DIRECTORY=$(dirname $i)
   FILEN=$(basename $i) 
   if [ -f $TARFILE ]
   then
        (cd $DIRECTORY ; tar rvf $TARFILE $FILEN)
   else
        (cd $DIRECTORY ; tar cvf $TARFILE $FILEN)
   fi
done
Something like this should do it.

The tar cvf creates the tar file tar rvf appends to that tar file. Doing the cd inside of parens spawns a separate shell and when it exits you are back in the same place.

Hope this helps!
 
  


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
Creating a spanning archive with tar Phyrexicaid Linux - Software 4 01-27-2005 09:04 PM
Problem Creating Archive With Tar In Redhat!!! hamidrh Linux - Newbie 4 09-16-2004 01:37 PM
Tar gives error when creating a tar file archive davidas Linux - Newbie 10 04-13-2004 01:35 AM
Problem creating tar.gz archive - File changed as we read it doctorwebbox Linux - General 1 02-04-2004 06:59 PM
this doesn't look like a tar archive .phister Slackware 5 02-01-2004 02:19 AM


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