0

I am trying to run this zip command on an Ubuntu WSL: zip -r /home/chansen/db-backup/backup.zip /mnt/c/data/db/*

I want the zip to contain all contents of db at the top level, but the resulting zip has those files nested inside all the parent directories. The zip file contains: mnt > c > data > db > myFiles. I just want the myFiles part to be at the top level without all those parent directories.

0

One way to accomplish this would be to cd into the db directory, then run your zip command using a relative path, like this:

cd /mnt/c/data/db/
zip -r /home/chansen/db-backup/backup.zip ./*
1
  • Wow, alright thanks! I didn't know the CWD actually mattered, I thought it just uses the last part of the path as the top level. – chrispytoes Jun 3 '20 at 18:32
0

Another approach is to use the -j option. Below is from the zip 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).

so in you case, you would do this

zip -r -j /home/chansen/db-backup/backup.zip /mnt/c/data/db/*

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.