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.

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?

share|improve this question

3 Answers 3

Maybe install fuse-zip, which is a very convenient tool. The following command:

fuse-zip abc.zip abc.mnt

will show the content of abc.zip in an abc.mnt directory. Then do whatever you want with the content of the directory:

cp -r ../seconddir/folder3 abc.mnt/

After that, unmount the directory:

fusermount -u abc.mnt; rm -rf abc.mnt

You're done.

share|improve this answer
It was really simple and it worked. –  blackfyre Aug 4 '14 at 13:23

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

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

share|improve this answer

I always roll with tar myself...

tar -cjf destination_archive_file.tar.bz2 /path/to/directory/to/archive

That would give ya a file 'destination_archive_file.tar.bz2' with all the contents within '/path/to/directory/to/archive' stored in it.

Then to extract, you just use:

tar -xjvf destination_archive_file.tar.bz2

Anyway, I know you blatantly asked for zip, not tar. I've tried zip a few times and found it to be a little counter-intuitive. Never did bother to really figure it out since I'd just use tar and get on with it. If you need to extrat a tar in Windows, 7-zip or winrar should do the trick. I'm pretty sure OSX supports it natively.

share|improve this answer

Your Answer


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.