Linux – Full path while zipping


I have the following files:



Then I use the following command:

cd ~
zip /Dir1/file1.txt /Dir2/file2.txt

In the I can see two directories (dir1 and dir2) but want only these two files (file1.txt and file2.txt) were in the root of!

I thought the -D option is what I need, but it doesn't work.

Best Answer

I think the -j option is what you want:

zip -j ~/Dir1/file1.txt ~/Dir2/file2.txt

From the man page:

-j     Store just the name of a saved file (junk the path), 
       and do not store directory names. By default, zip 
       will store the full path (relative to the current path).