Yes, these commands act differently. When you use zip
it will by keep the paths relative to how you ran the command, so running zip from different working directories will affect the result.
Example:
.
└── test
├── file1
├── file2
├── file3
└── foo
├── file4
└── file5
If I am in the root directory in this example and use the following command:
zip -r test.zip test/*
I get the following result:
$ unzip -l test.zip
Archive: test.zip
Length Date Time Name
--------- ---------- ----- ----
0 2019-11-08 16:51 test/file1
0 2019-11-08 16:51 test/file2
0 2019-11-08 16:51 test/file3
0 2019-11-08 16:53 test/foo/
0 2019-11-08 16:52 test/foo/file4
0 2019-11-08 16:53 test/foo/file5
--------- -------
0 6 files
However if I change directory into test
, and this command:
cd test
zip -r ../test2.zip *
I get the following zip file:
$ unzip -l test2.zip
Archive: test.zip
Length Date Time Name
--------- ---------- ----- ----
0 2019-11-08 16:51 file1
0 2019-11-08 16:51 file2
0 2019-11-08 16:51 file3
0 2019-11-08 16:53 foo/
0 2019-11-08 16:52 foo/file4
0 2019-11-08 16:53 foo/file5
--------- -------
0 6 files
Aside:
As an aside, if you do not have a directory structure, you can specify -j
which will remove all paths and store the files all in the root of the zip file:
# from the root of the example structure
zip -j test3.zip test/*
Produces:
$ unzip -l test3.zip
Archive: test.zip
Length Date Time Name
--------- ---------- ----- ----
0 2019-11-08 16:51 file1
0 2019-11-08 16:51 file2
0 2019-11-08 16:51 file3
0 2019-11-08 16:52 file4
0 2019-11-08 16:53 file5
--------- -------
0 5 files