I have linux hosting and wanted to zip everything in one single zip file but all time .htaccess file is excluded and other hidden files are not adding to zip file.
-
It's better if you don't create tarbombs.ams– ams2018-02-09 11:46:54 +00:00Commented Feb 9, 2018 at 11:46
-
4How are you creating the zip file?Jeff Schaller– Jeff Schaller ♦2018-02-09 11:53:33 +00:00Commented Feb 9, 2018 at 11:53
-
Use the dot to include current directory: $ cd /path/to/dir/project $ zip -r project.zip .jawira– jawira2018-11-21 11:18:13 +00:00Commented Nov 21, 2018 at 11:18
3 Answers
The easiest way is to tell your shell to include hidden files in globs. With bash this is done with shopt -s dotglob.
I suppose, you try something like
zip /path/to/your/zipfile *
but * doesn't match filenames starting with a dot. But ? matches a dot, so ?* matches all file names, including those starting with a dot. Unfortunally it also matches .., the parent directory, so do
zip /path/to/your/zipfile ??*
This will match everything in the current directory.
-
1Not in my case. Using Version 5.1.8(1)-release.Wu Wei– Wu Wei2022-01-12 19:46:43 +00:00Commented Jan 12, 2022 at 19:46
-
Wildcard expansion is done by the shell, the
zipversion is irrelevant. What is your shell and what files are missing in the archive?Philippos– Philippos2022-01-13 09:30:22 +00:00Commented Jan 13, 2022 at 9:30 -
I am sorry. I already stated the version, but forgot to mention bash. It is the version of bash I am using. Thank you.Wu Wei– Wu Wei2022-01-13 13:20:23 +00:00Commented Jan 13, 2022 at 13:20
-
2
??*won't match any single-character names. That may or may not be a problem, but it's worth saying explicitly so users can check whether that's needed.??* [^.]might be better for those cases.Toby Speight– Toby Speight2023-08-16 15:15:05 +00:00Commented Aug 16, 2023 at 15:15
One thing to note is if you are using a wildcard such as tar -cvpzf your_zip.tgz * it will not include hidden files. However, if you specify the directory such as tar -cvpzf your_zip.tgz /path/to/dir it will work. Or moreover, if you would like to run in your current directory:
tar -cvpfz your_zip.tgz --exclude=*.tgz .
-
They did say "zip" several times in the title, question, and tags, so a 'tar' answer a little off-target. Your idea is almost there, too -- when given a wildcard source, tar would actually include hidden files of subdirectories, just not (by default) of the current directory.2018-02-09 11:55:21 +00:00Commented Feb 9, 2018 at 11:55