Zip including hidden files
Asked Answered
C

8

110

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?

Carven answered 19/9, 2012 at 10:48 Comment(0)
F
204

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.

Fichte answered 19/9, 2012 at 10:50 Comment(5)
that pretty much works but now im also getting ../ which i dont think i want.Carven
by ../ you mean, you are also compressing files from the directory above?Fichte
apparently. When i do zip 1.zip * .* (in a folder with subfolder a and a hidden file called '.hidden_file') i get:Carven
adding: a/ (stored 0%) adding: ../ (stored 0%) adding: .hidden_file (stored 0%)Carven
or as you said, 'zip -r 1.zip .', which also works and is simpler.Carven
H
25

Or you can add more simple

zip 1.zip ./
Housefly answered 24/3, 2016 at 6:56 Comment(1)
you said zip -r 1.zip ./Attract
E
18

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

Eatables answered 5/8, 2015 at 7:3 Comment(4)
Thank you! That was exactly what I needed: a lot less troubles than manually calling zip.Euphonize
This approach doesn't include the .git/ directory thoughDorado
@Dorado If you needed something that was already git related, wouldn't you just clone it?Eatables
It would be nice for transferring with scpLylalyle
S
7

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"
Seminole answered 14/1, 2016 at 2:24 Comment(3)
How is your answer different to the accepted answer, which states "The correct way is zip -r 1.zip ."?Stripy
@SimonMᶜKenzie He also explained what "." means. That made the difference I suppose.Cental
The "." is NOT all files in folder. It means the "current folder" itself, which would ultimately include all its contents.Ladle
C
7

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

zip -r file.zip \.* *
Clericals answered 5/4, 2021 at 10:43 Comment(0)
S
2

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/

Speos answered 3/3, 2019 at 19:13 Comment(0)
O
1

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
Oestrogen answered 3/2, 2022 at 20:32 Comment(0)
D
1
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 "../*"

Donee answered 4/3, 2022 at 18:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.