How do I make the directories in a zip file relative to the target directory instead of my working directory

Posted by Nathan on Ask Ubuntu See other posts from Ask Ubuntu or by Nathan
Published on 2012-11-12T04:25:41Z Indexed on 2012/11/12 5:15 UTC
Read the original article Hit count: 265

Filed under:
|

I'm calling the zip command from a script where I cannot change directory. I need to make a zip file of the stuff in data/kit123/ from the directory which data resides in, but I want the contents of the zip to only be the contents of kit123, with paths relative to kit123.

This is the directory structure

myworkingdir
    data
        kit123
            kitpart1
                file.xcf
                anotherfile.xcf
            kitpart2
                ...
        kit124
            ...

My script runs in myworkingdir and cannot change directories.

If I call

zip -r kit123.zip data/kit123

then the structure in the zip file will be

data
    kit123
        kitpart1
            file.xcf
            anotherfile.xcf
        kitpart2

but I want it to be

kit123
    kitpart1
        file.xcf
        anotherfile.xcf
    kitpart2

Is there a zip option I can use to accomplish this? It seems odd that it should depend on my working directory

I know it's not -j. that one destroys the structure within kit123

© Ask Ubuntu or respective owner

Related posts about command-line

Related posts about zip