Zip command without turning on the compressed disk itself

Assume the structure:

/foo/bar/
        --file1
        --file2
        --file3
        --folder1
          --file4
        --folder2
          --file5

I want to run the unix zip utility , compressing the folder barand all its files and subfolders, from foo, but does not have a folder barinside the zip, using only the command line.

If I try to use the argument -j, it does not create the folder of folders inside the zip as I want, but does not create folder1and folder2. Execution -rjdoes not work.

(I know that I can enter the panel and do it. zip -r bar.zip .I want to know whether it is possible to do what $ / foo / bar / is zip -r bar.zip ., but to do it from $ / foo).

+4
source share
3 answers

zip -C ( ), tar.

:

cd folder1 && zip -r ../bar.zip *

bsdtar, tar libarchive, zips

bsdtar cf bar.zip - format zip -C folder1.

( . /- )

+6

cd /foo/bar, zip -r bar.zip ., :

# instead of: cd /foo/bar; zip -r bar.zip; cd -

( cd /foo/bar; zip -r bar.zip . )

() , cd .

sh .

Compound Commands
    A compound command is one of the following:

    (list) list is executed in a subshell environment (see COMMAND EXECUTION ENVIRONMENT below).  
           Variable assignments and builtin commands that affect the shell environment do not remain in effect after the command completes.  
           The return status is the exit status of list.
+8

. .

, .ods, XML . , OOo.

, : .ods OOo blank.ods, dir blank, :

cd blank && zip -r ../blank.ods *

, , , , && cd .. :

cd blank && zip -r ../blank.ods * && cd ..
+1

All Articles