Zip including hidden files

ZipHidden Files

Zip Problem Overview


In Linux I can zip all(except hidden files) in current directory by doing:

zip 1.zip *

But how do I include the hidden files?

Zip Solutions


Solution 1 - Zip

EDIT: The correct way is zip -r 1.zip .

The commands shown in my previous answer below are incorrect because they also include the parent directory.


Have you tried this:

zip yourfile.zip sourcedir/* .*

or you in your case

zip 1.zip * .[^.]*'

It should include all hidden files also.

Solution 2 - Zip

Or you can add more simple

zip 1.zip ./

Solution 3 - Zip

Just to be sure it is not forgotten since this is a forum for developers and a good number of us use git.

An easy way to get only what you want in the zip is to use git archive -o filename.zip branch

Solution 4 - Zip

If you want to zip all files (+hidden files) Kindly using: zip -r namefiles.zip . The "." is all files in folder.

zip -r namefiles.zip "folder will zip"

Solution 5 - Zip

On macOS 10.15.7 I had to separatelly add all dot leading files (\.*) and rest of the files (*):

zip -r file.zip \.* *

Solution 6 - Zip

if you don't have rights to save zip file in current dir you can go to dir where you have rights and type

zip -r 1.zip /path/to/source/dir/.

However when if in .../some_dir you type

unzip 1.zip

then your files will be decompress into .../some_dir/path/to/source/dir/

Solution 7 - Zip

If you'd like to save some subdirectory of the current directory recursively with hidden and regular files just type

$ zip -r backup_subdirectory.zip backup_subdirectory/. backup-subdirectory/*

And for unzipping:

$ unzip backup_subdirectory.zip 

Or even simpler by using tar for creating an archive:

$ tar czvf backup_subdirectory.tar.gz backup_subdirectory/

And for extracting all files from the archive:

$ tar xzvf backup_subdirectory.tar.gz

Solution 8 - Zip

zip -r 1.zip .* -x "../*"

Just doing zip -r 1.zip .* will include the parent folder as well so the trick is to exclude the parent folder using -x "../*"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionjohn-jonesView Question on Stackoverflow
Solution 1 - ZipGunnarView Answer on Stackoverflow
Solution 2 - ZippictoruView Answer on Stackoverflow
Solution 3 - ZipcodeView Answer on Stackoverflow
Solution 4 - ZipD zView Answer on Stackoverflow
Solution 5 - ZipViliam JobkoView Answer on Stackoverflow
Solution 6 - ZipKamil KiełczewskiView Answer on Stackoverflow
Solution 7 - ZipVitaliiView Answer on Stackoverflow
Solution 8 - ZipArpan SarkarView Answer on Stackoverflow