Search code examples
bashzip

How to ZIP files without subdirectories inside the ZIP?


I have CSV files inside data/processed/:

data
  processed
     file1.CSV
     file2.CSV
     file3.CSV
     file4.CSV
     file5.CSV

and I want to create an archive with all these 5 files:

data.ZIP
     file1.CSV
     file2.CSV
     file3.CSV
     file4.CSV
     file5.CSV

I tried to execute this command:

!zip -r data.zip data/processed/

However, the ZIP file looks as follows:

data.zip
    data
        processed
              file1.CSV
              file2.CSV
              file3.CSV
              file4.CSV
              file5.CSV

Solution

  • Use -j to ignore all path information. From the man page:

       -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).