Find the answer to your Linux question:
Results 1 to 2 of 2
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 ...
  1. #1
    Just Joined!
    Join Date
    Dec 2009
    Posts
    2

    Need 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.
    Code:
    #!/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

  2. #2
    Just Joined!
    Join Date
    Dec 2009
    Posts
    2
    A fellow poster provided solution:
    Code:
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...