Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get list of filenames from file and fetch and tar the files 1

Status
Not open for further replies.

milage

Programmer
Jul 13, 2001
58
US
Hi,

I'm kinda new to shell scripts.

I have a file which lists a series of filenames. I need to write a script which gets the list of these filenames from the file, and then tars them up maintaining the directory structure.

Cheers

Rob
 
If your list of files are already inclusive of the path
ie
/u/fred/abcd
/u/bert/fghi
/u/joe/hjkl
etc
then :
tar -cvf tarfilename `cat filelist`

HTH ;-) Dickie Bird

Honi soit qui mal y pense
 
Hi,

Cheers for that. However, what can I do if they aren't in the path.

sample file contains:

directory1/directory2/filename
directory2/directory3/filename
directory3/filename

and these are not in the root or the path.

So, what I need to do is to add the rest of the path to each filenames which is an environment variable eg $A_PATH


$A_PATH/directory1/directory2/filename
$A_PATH/directory2/directory3/filename
$A_PATH/directory3/filename

and thhen tar up all the files into one lovely archive.

Hope this is possible!

Rob


 
Something like this should do it
Code:
ORIG_PATH=`pwd`
cd $A_PATH
tar -cvf tarfilename `cat $ORIG_PATH/filelist`
cd $ORIG_PATH
//Daniel
 
Another alternative is to use the -C option:

Code:
tar -cvf <tarfilename> -C $A_PATH `cat filelist`

Cheers, Neil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top