Create Tar file with a new prefix directory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • keydrive
    New Member
    • Oct 2007
    • 57

    Create Tar file with a new prefix directory

    Hi,

    What is the cleanest way to create a tar with a prefix directory in it?

    cd /export/home/testbed
    tar -cvzf test.tgz *

    I need the tar to include "jump"/testbed/<files> in it not just testbed/<files> in it.

    There are sed commands out there but I am in search of a cleaner way.

    Thanks
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    what do you mean by 'cleaner way'?

    Code:
    mkdir testbed
    cd testbed
    tar xvfz ../test.tgz
    cd ..
    tar cvfz test-newt.tgz testbed/*
    maybe you even could end with: rm -r testbed

    Comment

    • keydrive
      New Member
      • Oct 2007
      • 57

      #3
      "cleaner way" meaning the least amount of code.

      Can the structure within a tar be changed?

      directory testbed contains files and subfolders. The directory testbed name needs to be tared with a new name testdone rather than testbed. i.e.

      testbed/testing/tester/
      to
      testdone/testing/tester/

      I don't see an option in tar man or online to change or modify the path inwhich the tar is stored.

      Comment

      • Luuk
        Recognized Expert Top Contributor
        • Mar 2012
        • 1043

        #4
        i do not think that this is possible without temporarily extracting files from the tar-archive

        Comment

        Working...