Zip all files in a directory, but don't include the top directory in the archive

36,628

Solution 1

cd /path/to/your/folder/www
zip -r filename.zip *

Optionally

mv filename.zip /some/other/path

Solution 2

7z a -tzip filename.zip -w /var/www/.

Hidden files included.

Share:
36,628

Related videos on Youtube

Svish
Author by

Svish

Software Developer, Geek, HSP, SDA, ..., open, honest, careful, perfectionist, ... Currently into indoor rowing and rock climbing, just to mention something non-computer-related... Not the best at bragging about myself... so... not sure what more to write... 🤔

Updated on September 18, 2022

Comments

  • Svish
    Svish over 1 year

    Can't quite figure out how to do this right. I have a folder with a website in /var/www

    I want to create a zip file with all of it, which when I decompress it does not include the top directory. In other words, the "top" of the zip file should not be the www directory, but the files inside that directory. Hope that made sense...

    Reason why I need it is because I need to upload my website as a zip file and then unzip it in place. And won't work if it then unzips to webroot/www/ instead of webroot/.

    Any able to help with how to do this correctly in the terminal?

    • Ƭᴇcʜιᴇ007
      Ƭᴇcʜιᴇ007 over 12 years
      Which commands and arguments are you using to make the Zip?
  • Svish
    Svish over 12 years
    Will this include hidden files?
  • Joshua Robinson
    Joshua Robinson about 8 years
    * does include hidden files.
  • Trevor Sullivan
    Trevor Sullivan about 7 years
    What if I don't want to cd to the directory first?
  • kodlan
    kodlan almost 4 years
    zip -r -j filename.zip folder_name
  • Jeppe
    Jeppe about 3 years
    @kodlan Thanks! You should add this as an answer. The -j argument solved it for me. From man zip: Store just the name of a saved file (junk the path), and do not store directory names. By default, zip will store the full path (relative to the current directory).
  • sny
    sny almost 3 years
    Does not include hidden file/folders