4

I have to compress only the contents of the folder, not the folder with tar, there is any argument for that? I have search but I don't find anything.

Example:

 mainfolder/
     asd1
     asd2
     subfolder/
     ....
     asdN

In my tar I want this:

  asd.tar.gz/
     asd1
     asd2
     subfolder/
     ....
     asdN

2 Answers 2

4

CD to "mainfolder" then execute

tar cvfz /path/your.tgz ./*
3
  • I want to do this out of this folder, because I am using a python script
    – tato469
    Oct 17, 2013 at 8:50
  • 1
    finally I did using os.chdir() (That is like cd in python) thanks. Here your first check here and welcome :)
    – tato469
    Oct 17, 2013 at 8:53
  • 1
    Why don't you use a python tar library? This is the more sophisticated way instead of using a system call.
    – noggerl
    Oct 17, 2013 at 8:59
0

I've been searching for something similar and coming up empty. Finally found a solution on my own I wanted to share.

  1. Got into target folder: cd FOLDER
  2. Archive contents or target folder and place archive in parent folder: tar -cvf ../FOLDER.tgz *
  3. Go back to parent folder: cd ..

Or all at once (replace FOLDER): cd FOLDER && tar -cvf ../FOLDER.tgz * && cd ..

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .