4

I'm trying to make a zip file out of some files but when I extract the zip I only get 1 file.

tar cfvz test.zip file1.mp3 file2.mp3 file3.jpg

And after I extract test.zip I only get a "test" file.The size of the zip size is ok, I just don't know how to make this work so that on extract I get the same files:"file1.mp3 file2.mp3 file3.jpg"

4
  • A test file, or a test folder?
    – Linuxios
    Jun 28, 2012 at 13:41
  • Just a test file.
    – user1217380
    Jun 28, 2012 at 13:44
  • Odd. I have no clue.
    – Linuxios
    Jun 28, 2012 at 13:44
  • do you confuse .zip and .gz on purpose?
    – akira
    Jun 29, 2012 at 4:22

3 Answers 3

4

This worked for me:

$ tar -czvf test.tar.gz ./file1 ./file2 ...

$ tar -tzf test.tar.gz
./file1
./file2

# to extract do:
$ tar -xzf test.tar.gz

After passing f option you should give the filename of the archive you are creating.

Oh, and in case you are using zip to unzip the file, you wont get a directory but you will get a tarball instead. Tarball contains all your files. Use:

tar -xf test

And you should see all your files.

If you'd like to have normal zip files, use zip command instead of tar/gz tandem. Also it is a good practice to add correct file suffix:

  • tar with gzip (i.e. tar czvf ...): filename.tar.gz
  • tar with bzip2 (i.e. tar cjvf ...): filename.tar.bz2
  • tar without compression (i.e. tar cvf ...): filename.tar
3
  • to create a tar.gz use: tar czvf file.tar.gz /folder to extract: tar xzvf file.tar.gz . sometimes it's better to use quotes "file1 file2 file3"...
    – Thomas
    Jun 28, 2012 at 13:46
  • @Thomas sure you can do it without - but who cares ;) works either way.
    – bcelary
    Jun 28, 2012 at 13:48
  • I need the .zip file.I've created some symbolic links and I'm trying to do the same thing using "zip --symlinks" like "tar -h " but it doesn't work.Can you help?
    – user1217380
    Jun 28, 2012 at 14:16
3

First, even if you have named your compressed file .zip, it is not a ZIP file but a TAR & GZIP file, so the correct file extension to use would be .tar.gz or .tgz.

Now, what is the command you used to extract the compressed file? If you used a ZIP utilities, it may have been confused by the extension and only uncompressed the file without untarring it. That would explain why the result is a single file, which is actually a TAR file. If you use an untar utility (or the command tar -xf test), you should get back all your file from within.

1
  • you are right.The only reason I used tar is because I haven't found a way to use zip with symbolic links.
    – user1217380
    Jun 28, 2012 at 14:22
-1

To extract the files you should do

tar xvfz test.zip 

and by default all files will pop out from the path relative to where you are so if test.zip contained myfile.txt dir1/myfile.txt both files would come out the zip

1
  • Correct. Looks like OP is unzipping tarballs with something like winzip/unzip instead of tar/gz.
    – bcelary
    Jun 28, 2012 at 13:54

You must log in to answer this question.