tags:

views:

27

answers:

2

Suppose the structure:

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

I want to run the unix zip utility, compressing the bar folder and all of it's files and subfolders, from foo folder, but not have the bar folder inside the zip, using only command line.

If I try to use the -j argument, it doesn't create the bar folder inside the zip as I want, but doesn't create folder1 and folder2. Doing -rj doesn't work.

(I know I can enter inside bar and do zip -r bar.zip . I want to know if it's possible to accomplish what $/foo/bar/ zip -r bar.zip . but doing it from $/foo).

A: 

Why is the presence of the bar folder in the zip file a problem? It takes up very little space (I measured it as about 150 bytes). Even if it is omitted, the extract creates the directory when necessary (tested on MacOS X 10.6.4).

To answer the question, one of:

zip bar.zip bar/*
zip -r bar.zip bar/*
Jonathan Leffler
+1  A: 

zip doesn't have a -C (change directory) command like tar does

you can do: cd folder1 && zip -r ../bar.zip * from within a command line shell

or you can use bsdtar which is a version of tar from libarchive that can create zips

bsdtar cf bar.zip -C folder1 . (this creates a folder called ./ -- not sure a way around that)

Mark Harviston
Somebody still uses you MS-DOS