Linux – zip command on linux how to force to zip only files and not whole directories structure

linuxzip

I want just stupid, simple thing. ZIP all the content of given directory.

What I get as result of:

zip -r /home/andi/MEDIA_DUMPS/xyz_media.zip /home/andi/xyz/mega_backend/mega_www/media

Is following:

➜  home  tree -L 5
.
└── andi
    └── xyz
        └── mega_backend
            └── mega_www
                └── media
                    ├── csv
                    ├── editor
                    └── img

while I want just this:

➜  media  tree -L 1
.
├── csv
├── editor
└── img

MY AD-HOC WAY AROUND USING TAR:

tar -cjf /home/andi/MEDIA_DUMPS/xyz_media.tar.gz -C /home/andi/xyz/mega_backend/mega_www/media .

based on: https://stackoverflow.com/questions/18681595/tar-a-directory-but-dont-store-full-absolute-paths-in-the-archive

Best Answer

How do I to zip only files and not the whole directory structure?

Use the -j (junk-paths) option.


zip: Package and compress (archive) files

-j
--junk-paths
      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).

...

You may want to make a zip archive that contains the files in foo, without recording the directory name, foo.

You can use the -j option to leave off the paths, as in:

zip -j foo foo/*

Source zip: Package and compress (archive) files:

Related Question