7zip destination folder -o

54,031

Solution 1

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

Solution 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

Solution 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.

Share:
54,031

Related videos on Youtube

Pixeli
Author by

Pixeli

Updated on September 18, 2022

Comments

  • Pixeli
    Pixeli over 1 year

    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.

    • Admin
      Admin about 9 years
      Are you getting some errors?
    • Admin
      Admin over 5 years
      @ElderGeek: a space after -o leads to error Too short switch: -o.
    • Admin
      Admin over 5 years
      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)
  • mchid
    mchid about 9 years
    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
  • Ron
    Ron about 9 years
    @Pixeli can you mark it as 'answered' if my post indeed did answer your questions?
  • user3804598
    user3804598 over 6 years
    imho, unusual syntax that path goes immediately after -o switch, e.g. -o/home/userName/Downloads
  • user3804598
    user3804598 almost 5 years
    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)