I have wondered a long time how to do this and read already many manuals but dont get this to work. I want to zip with 7zip a folder to specific destination. There is in manual a guide to use -o{folder} but how does it really work?


7z a -t7z serverx /home/example/folder -o/home/backups/folder1

How to use that -o? Destination folder exists.

  • Are you getting some errors? – Ron Apr 29 '15 at 13:50
  • @ElderGeek: a space after -o leads to error Too short switch: -o. – Frank Nocke Nov 3 '18 at 10:42
  • NOTE: tilda ~ appears not to be resolved for some reason, use -o/home/frank/someFolder rather than -o~/someFolder. (encountered on a perfectly normal Ubuntu 18.04 with 7-zip 16.02) – Frank Nocke Nov 3 '18 at 10:44

From man 7z:

          Set Output directory

It is basically the destination directory for extracting the archive. All the extracted files will be saved in the given directory. This option won't be used in case of creating the archive.

Here is an example:

$ 7z a -t7z check.7z file.txt -ofoo/
Creating archive check.7z
Compressing  file.txt      
Everything is Ok

$ ls
check.7z  file.txt  foo

$ 7z x -t7z check.7z -ofoo/
Processing archive: check.7z
Extracting  file.txt
Everything is Ok
Size:       180
Compressed: 221

foo$ ls
  • 2
    imho, unusual syntax that path goes immediately after -o switch, e.g. -o/home/userName/Downloads – user3804598 Jan 6 '18 at 18:04
  • tnx. ugly syntax where the path goes immediately after -o. It also doesn't understand tilde '~' as a home directory (you can't use -o~/some_path) – user3804598 Jun 16 at 5:57

To add all files from directory /home/example/folder to archive archive.7z in /home/backups/folder1 use:

7z a -t7z /home/backups/folder1/archive.7z /home/example/folder

-0 switch specifies a destination directory where files are to be extracted.

  • I think the reason it's confusing is how the destination path is listed before the source directory to be compressed as it usually source > destination – mchid Apr 29 '15 at 19:11
  • @Pixeli can you mark it as 'answered' if my post indeed did answer your questions? – Ron Apr 30 '15 at 3:58

To extracts into a directory, you must remove any spaces after the -o for example,

Extract zip file into a new or existing directory dir1:

7z x file.zip -o./dir1

Compress directory dir1 to a new zip file:

7z a newfile.zip ./dir1

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.