LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-07-2009, 11:37 AM   #1
mj12net_brian
LQ Newbie
 
Registered: Dec 2009
Posts: 3

Rep: Reputation: 0
Please help with tarball script


The following script is supposed to look at a list of files and folders and tar them all up. Ofcourse you have to strip off everything to the left of the file or folder to tar only that object. My problem is that when I do that my script no longer knows how to find the file or folder. Is there a way of saving in a variable the location of the object you want to tar and have it passed to the for loop with each iteration. I'm trying to stay away from nested loops. Thanks in advance for your help.

#!/bin/bash
for p in `cat /data/results/filelist`
do
i=`echo $p | awk 'BEGIN{FS="/"}{print $NF}'`
cd $p && tar czf ../$i.tar.gz $i
done

filelist below:

/data/results/solid0155/solid0155_20090918_2x35_LMP_FC2
/data/results/RegressionDriver/CaseManager/tests_era2/cases/performance/155_2x35
_FC2_run_outputs_tillSam
/share/reference/genomes/chromFa/hg18_validated.fasta
/data/results/README
 
Old 12-07-2009, 11:46 AM   #2
HaroldWho
Member
 
Registered: Nov 2006
Location: southeastern PA
Distribution: Slackware
Posts: 130

Rep: Reputation: 23
Is there some reason why you can't just use the
Code:
--files-from /data/results/filelist
option for tar?
 
Old 12-07-2009, 11:56 AM   #3
mj12net_brian
LQ Newbie
 
Registered: Dec 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by HaroldWho View Post
Is there some reason why you can't just use the
Code:
--files-from /data/results/filelist
option for tar?
I didn't even know there was such an option. If it works I'll use it in the future. Thanks.
 
Old 12-07-2009, 12:38 PM   #4
mj12net_brian
LQ Newbie
 
Registered: Dec 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Your solution worked:

tar czf tarball.tar.gz --files-from /data/results/fileslist

filelist below:

/data/results/a/file1
/data/results/a/b/file2
/data/results/a/b/c/file3
/data/results/a/b/c/d/file4
/data/results/a/test1
/data/results/a/b/test2
/data/results/a/b/c/test3
/data/results/a/b/c/d/test4

You end up with:

[root@offline01 results]# ls -ld tarball.tar.gz
-rw-rw-r-- 1 root users 273 Dec 7 11:18 tarball.tar.gz
 
  


Reply



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
Tarball with links xeon123 Linux - General 7 02-28-2007 09:01 AM
About compressed tarball satimis Linux - Software 6 06-25-2006 08:39 AM
After Tarball then what ? sevvy8 Linux - Newbie 2 03-29-2004 03:41 AM
How do you install from a tarball? HoosTrax Linux - Software 3 02-10-2004 12:34 PM
Tarball? HardcoreGamer Linux - Software 4 02-12-2003 02:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:06 AM.

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
Open Source Consulting | Domain Registration