1

Purpose: zip a folder in window and extract it in linux.

I prefer to https://superuser.com/a/898508/1451256 and I realize there is no description for -a option in tar.exe --help: https://ss64.com/nt/tar.html , so I just follow as the tar official: "tar -cvzf xxx" but when I've tried to extract that zip file in linux by "unzip xxx", it throws error " End-of-central-directory signature not found. Either this file is not a zipfile, or it constitutes one disk of a multi-part archive. In the latter case the central directory and zipfile comment will be found on the last disk(s) of this archive. "

So I suspect the zip file is not zipped properly, then I try to add -a option, it works perfectly. As comment from https://superuser.com/a/1473257/1451256 : it says without the -a option "it assumes a plain tar archive", I don't know what it means. Can someone explains what is the -a option? Thanks.

1 Answers1

2

tar(1):

...
-a, --auto-compress
             (c mode only) Use the archive suffix to decide a set of the
             format and the compressions.  As a simple example,
                   tar -a -cf archive.tgz source.c source.h
             creates a new archive with restricted pax format and gzip
             compression,
                   tar -a -cf archive.tar.bz2.uu source.c source.h
             creates a new archive with restricted pax format and bzip2
             compression and uuencode compression,
                   tar -a -cf archive.zip source.c source.h
             creates a new archive with zip format,
                   tar -a -jcf archive.tgz source.c source.h
             ignores the "-j" option, and creates a new archive with
             restricted pax format and gzip compression,
                   tar -a -jcf archive.xxx source.c source.h
             if it is unknown suffix or no suffix, creates a new archive with
             restricted pax format and bzip2 compression.
...
Tom Yan
  • 9,075
  • 2
  • 17
  • 36
  • Teach the boy to fish Tom! :-) "help" is a built-in command of the Bash Shell, documenting commands for that shell. "man" manual pages are the system-wide doumentation system, traditionally of Unix. "info" is yet another, originating from the GNU project... all 3 overlap, but generally "man" is the most readily accessible/comprehensive. So next time, just use "man tar", and here's the online equivalent of that command... www.gnu.org/software/tar/manual/ – user1138 Jun 29 '21 at 10:34
  • @user1138 Well, I linked `tar(1)` to the page on man7.org...and yeah if he's on cygwin / msys2 he can probably get man-db or so as well to use `man`. – Tom Yan Jun 29 '21 at 10:42
  • All good "man"! (boom-tish) I'll see myself out now... – user1138 Jun 29 '21 at 10:47
  • thanks all for the information, Sorry but I still don't get it, the link tar(1) belongs to linux, right? What I use is tar.exe, are they the same? What is the different of the zip file when using -a option and not using it? – Zx binhjy xZ Jun 30 '21 at 14:58
  • Well I have no idea where/how you get it but most likely it's GNU tar anyway (the other popular variant being bsdtar in libarchive). Use `--version` to find out if you want to. – Tom Yan Jun 30 '21 at 15:37
  • Note that extension name is always just a *hint*. It does not necessarily reflect what the type the file really is of. If you don't instruct tar to create a zip file with a switch (e.g. -a), it will create a (uncompressed) tarball no matter what you name it (.txt, .exe, .jpg, all the same). – Tom Yan Jun 30 '21 at 15:42
  • Btw you do realize there could be different builds for the same software (source) for different platforms/OSes, do you? – Tom Yan Jun 30 '21 at 15:46
  • yep, it is: bsdtar 3.3.2 - libarchive 3.3.2 zlib/1.2.5.f-ipp, the tar command I also reference from: https://techcommunity.microsoft.com/t5/containers/tar-and-curl-come-to-windows/ba-p/382409. Thanks for the explanation, I have better understanding now. Regarding different builds for same software: I don't get what you mean? Do you mean different OS like window/linux have different way to kind of read/extract/compress the file? – Zx binhjy xZ Jul 04 '21 at 17:15
  • No, I mean generally speaking the same piece of code can often be compiled on/for different OSes, e.g. Windows *and* Linux, so `the link tar(1) belongs to linux, right` is not necessarily a thing. – Tom Yan Jul 04 '21 at 21:54
  • Ya, something like cross framework, is it? So it will work on both linux and window huh? Another question related with my understanding, please correct me 1/ if I use tar to zip in windows without -a - unzip with tar in windows: success - unzip with 7 zip in windows: fail - unzip with tar in linux: success - unzip with unzip in linux: fail Is it? 2/ so for every soft that from gnu, to check the usages we should use "man xxx"? – Zx binhjy xZ Jul 05 '21 at 15:52
  • Not necessarily. For example both GNU tar and libarchive are written in C. (But there are platform-specific code/hack in them.) Whether you can use a specific program to *extract* from a zip file depends on whether it support the zip format, and if that's the case, whether it is *really* a zip file (and if it is not, but a tarball, whether the program supports extracting from a tarball). It really isn't relevant the the OS. (And again, it simply will NOT be a zip file unless you tell `tar` with e.g. `-a` to create a zip file.) – Tom Yan Jul 05 '21 at 16:07
  • `man` is pretty much the standard way to read a manual (or "man page") of a program in Linux (and most other UNIX-like systems). If you are using cygwin / msys2 in Windows, you can probably rely on that as well. (But AFAIK Windows itself has not shipped the `man` program.) Also, the GNU project sort of endorse/prefer another form of manual, which is their own GNU info. (But their programs have man pages as well, just sometimes simplified.) – Tom Yan Jul 05 '21 at 16:12
  • Thanks a lot for your input – Zx binhjy xZ Jul 08 '21 at 05:24