21

The zip command generally places the output zip file in the current directory. But, I'm wondering if there is an option that I'm overlooking in the man page that lets me specify the destination directory for the output archive file.

This created 'my_archive' in the current directory:

zip -rT my_archive dir_to_be_archived

But, I want to be able to place 'my_archive' under ./my_backups without having to 'cd' into that backups directory. Is there something like:

zip -rt my_archive dir_to_be_archived --destination ./my_backups
nemo
  • 1,504
  • 3
  • 21
  • 41

1 Answers1

40

You can specify the destination path directly:

zip -r /path/to/destination.zip /files

Keep in mind that the destination should not be in the same directory as the files that you are zipping up.

Michael Hampton
  • 9,737
  • 4
  • 55
  • 96
  • 2
    It appears to require the path to exist - is it possible to have it created as part of the command? – Jeppe May 03 '20 at 15:02
  • 2
    @Jeppe you can easily create it with `mkdir -p /path/to && zip ...` – Le Sir Dog Mar 07 '21 at 12:05
  • Adjecent to this question, relative directories also work. `zip -r ../app.zip .` will put files in the current directory in a .zip in the parent. – Joe Sadoski Oct 17 '22 at 19:08