Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there an option on linux zip command such that I can hard code the target directory it unzips into. For example, I would like to zip ./mydir files into myzipfile.zip but I want the unzip command to create a specific directory "projx" and expand the files which were under ./mydir to it.

zip -r myzipfile.zip mydir (-option to expand into 'projx' when unzipped? )
share|improve this question
    

2 Answers 2

up vote 5 down vote accepted

There is no such option, at least not for Info-ZIP. You have to create a directory named projx in the first place, move/copy your files into it and then pass it to zip. Another solution would be to pass option -d to unzip for specifying the target directory for extraction.

share|improve this answer

I don't know about a specific command line option, but you can use the following commands to reach you goal:

ln -s mydir projx
zip -r myzipfile.zip projx
rm projx

The first command creates a symbolic link, so that you can access the files in mydir also via projx. Then using Info-ZIP (tested with version 2.31) the symbolic link is dereferenced (this is the default, unless you specify -y) and the files are stored recursively:

adding: projx/ (stored 0%)
adding: projx/foo.1 (deflated 23%)
adding: projx/bar.2 (deflated 73%)
...

You see, the folder name is stored in the file, too -- so upon extraction the directory projx is created.

However, I can't think of a possibility to store absolute paths, but this is a bad idea anyway.

share|improve this answer
    
Absolute path only works on MacOS by specifying option -jj. On other operating systems only option -j is supported (and -jj is interpreted as -j) which removes any leading path and thus leading to the opposite (a very clever design...). –  scai Jul 10 '13 at 8:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.