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.

roaima
  • 107,089
  • 14
  • 139
  • 261
Parth Kundariya
  • 59
  • 1
  • 1
  • 4

3 Answers3

6

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

Ignacio Vazquez-Abrams
  • 44,857
  • 7
  • 93
  • 100
3

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.

Philippos
  • 13,237
  • 2
  • 37
  • 76
  • 1
    Not in my case. Using Version 5.1.8(1)-release. – Wu Wei Jan 12 '22 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? – Philippos Jan 13 '22 at 09: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 Jan 13 '22 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 Aug 16 '23 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 .
Jaken551
  • 565
  • 3
  • 9
  • 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. – Jeff Schaller Feb 09 '18 at 11:55