17

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?

Example:

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

How to use that -o? Destination folder exists.

Pixeli
  • 171

3 Answers3

19

From man 7z:

   -o{Directory}
          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
file.txt
heemayl
  • 93,925
7

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
Benny
  • 5,100
3

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.

Ron
  • 20,938