Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

My folder structure inside a zip file is:

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

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

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

  1. It would move into 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 and sit at the same level as folder1 and folder2 instead of replacing the textfile.txt within

My question is - I want to replace the with the one inside seconddir/folder3/textfile.txt.

How do I achieve this via the command line interface?

share|improve this question

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

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

fuse-zip abc.mnt

will show the content of 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 textfile.txt

share|improve this answer

You must log in to answer this question.

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