Linux – How to insert a folder into a ZIP file

command linelinuxzip

I'm a newbie on Linux and had to do something like this with the zip command:

My folder structure inside a zip file abc.zip is:

-- currentdir
  -- onestepdeep
     -- abc.zip
       -- folder1
         -- textfile.txt
       -- folder2
  -- seconddir
    -- folder3 
      -- textfile.txt

I need to copy the file textfile.txt from the seconddir/folder3 into folder1 inside abc.zip

I could move textfile.txt into abc.zip with the following outcomes:

  1. It would move into abc.zip as folder3/textfile.txt (the hierarchy preserved)
  2. Also used a -j switch (help said it junked the path info and it did but) – it would move only into abc.zip and sit at the same level as folder1 and folder2 instead of replacing the textfile.txt within abc.zip/folder1

My question is – I want to replace the abc.zip/folder1/textfile.txt with the one inside seconddir/folder3/textfile.txt.

How do I achieve this via the command line interface?

Best Answer

I also use tar, but if you require zip then:

zip -b path/to/create/in zipfile.zip textfile.txt

Related Question