7Zip Destination Folder -O

7Zip Destination Folder -O

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.

3

3 Answers

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
2

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

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.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova
Author

Elena Rostova

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.