0

I have the following file structure:

cwd/
    ---dir1
       ---file_name1
       ---some_file_name
    ---dir2
       ---file_name1
       ---some_other_file_name
    ---some_file

I want to get zip file such that when I unzip I get cwd directory and NOT pwd directory. So according to the man I need to use -j flag. But when I use him in this case (OS X mac unix) I got error regarding the issue I have in 2 different directories same file name (file_name1 in the example).

zip error: Invalid command arguments (cannot repeat names in zip file).
first full name...
second full name...
this my be a result of using -j 

According to this it seems nothing can be done and this is how zip -j works. How can I still achieve the requirement of compressing the zip without the default pwd file structure? (I cannot rename the files - there is a reason why from the beginning I use zip via shell etc...).

Thanks,

3
  • I don't quote understand your question. Of course you cannot store two files with the same name into a zip. What is the result you're trying to achieve, how should the zip look like?
    – cbley
    Sep 22, 2015 at 11:15
  • @cbley Exactly as if I used Microsoft Windows Explorer and right clicked on the folder called cwd and select comprees to zip - I get cwd.zip file, containing in the root dir1, dir2 and some_file, and inside dir1 and dir2 their files. Right now I get cwd.zip but when I unzip it I get pwd structure until I cd to actually needed files - this is redundant.
    – michael
    Sep 22, 2015 at 11:26
  • tar archives support files with the same name Feb 26, 2021 at 17:35

1 Answer 1

1

So, you don't want to junk the paths, but just ignore the top-level directory?

 cd cwd ; zip -r ../cwd.zip .
10
  • Not it's not working. When I unzip the file cwd.zip I get for example: users/name/documents/cwd/files... I need when I unzip to get cwd/files. When I do it on windows ain't problem that in 2 different dirs same file name
    – michael
    Sep 22, 2015 at 11:33
  • I think -j flag is the general solution for that but according to the link in the original question it struggles with case of 2 same file names in different dirs, and some creative solution needed
    – michael
    Sep 22, 2015 at 11:36
  • 1
    You probably did something wrong. -j is definitely not what you want. When I execute zip -r ../cwd.zip . the created zip file contains dir1, dir2 and some_file in the root, and file_name1 in each of dir and dir2. Maybe you did something wrong when unzipping? How do you unzip?
    – cbley
    Sep 22, 2015 at 12:00
  • 1
    Have you installed the unzip program? Look at the output of unzip -l cwd.zip. Amend your question with the output and tell us what you expected instead in case this is wrong.
    – cbley
    Sep 22, 2015 at 13:10
  • 1
    Do you have, by chance, the ZIPOPTS environment variable defined? If so, does it include the -jj option? Which version of zip do you have installed?
    – cbley
    Sep 23, 2015 at 6:19

Not the answer you're looking for? Browse other questions tagged .