3

I have a web app in this path

var/app/current

I use this command to zip everything including hidden files like htaccess

zip -r yourfile.zip * .*

It generates the zipped file which contains the web app files and folders in addition to a folder named current which contains another copy of the web app files and folders.

How can I compress web app files and folders including hidden files without including the directory named 'current' as a duplicate.

5

You may not use .*, because that shell glob will also match . and .. (current and parent directory), causing the behaviour you described.

But it isn't necessary anyway, you can just use the zip -r option on its own. Let me quote the manual page man zip:

   -r
   --recurse-paths
          Travel the directory structure recursively; for example:

                 zip -r foo.zip foo

          or more concisely

                 zip -r foo foo

          In this case, all the files and directories in foo are saved  in
          a zip archive named foo.zip, including files with names starting
          with ".", since the recursion does not use the shell's file-name
          substitution  mechanism.  If you wish to include only a specific
          subset of the files in directory foo and its subdirectories, use
          the  -i  option  to specify the pattern of files to be included.
          You should not use -r with the name  ".*",  since  that  matches
          ".."   which will attempt to zip up the parent directory (proba‐
          bly not what was intended).

          Multiple source directories are allowed as in

                 zip -r foo foo1 foo2

          which first zips up foo1 and then foo2, going down  each  direc‐
          tory.

          [...]

So you just specify the folder you want to zip, like:

zip -r yourfile.zip /var/app/current

Or if your current directory already is /var/app/current, just:

zip -r yourfile.zip .
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.