4

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.

3
  • It's better if you don't create tarbombs. Commented Feb 9, 2018 at 11:46
  • 4
    How are you creating the zip file? Commented Feb 9, 2018 at 11:53
  • Use the dot to include current directory: $ cd /path/to/dir/project $ zip -r project.zip . Commented Nov 21, 2018 at 11:18

3 Answers 3

6

The easiest way is to tell your shell to include hidden files in globs. With bash this is done with shopt -s dotglob.

4

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.

4
  • 1
    Not in my case. Using Version 5.1.8(1)-release. Commented Jan 12, 2022 at 19:46
  • Wildcard expansion is done by the shell, the zip version is irrelevant. What is your shell and what files are missing in the archive? Commented 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. Commented 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. Commented Aug 16, 2023 at 15:15
1

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 .
1
  • 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. Commented Feb 9, 2018 at 11:55

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.