0

I have a zipped folder with many directories and I am wondering how would they be unzipped if I were to execute the unzip command with no arguments. An example would be:

home
|---user1
    |---dir1
        |--- file01
        |--- file02
|---user2
    |---dir2
        |---file03
        |---file04

Let's say I zipped both /home/user1/dir1/* and /home/user2/dir2/* in one location and transferred it to another server that has the paths /home/user1 and /home/user2. If I transferred the zipped file to /root and executed unzip folder.zip, what would happen? And how would I get those directories in the same paths in server 2 as they were in server 1?

The whole point is that I have similar environments and I want to be able to transfer from one server to the other a few files but not the entire directory and would I be able to use zip for that, or do I need to zip to one temporary location and then move as necessary.

1 Answer 1

0

What happens? When you read man unzip, it says the default (with no options) extracts into the current directory (and subdirectories below it) all files from the specified ZIP archive, creating the subdirectories if they do not exist.

If you want the files extracted into exactly the same path as they came from. you would need to have rights in the destination path. If you do, and you specify the destination for extraction with the -d and specify the destination, the files will be written there.

2
  • It is bad practice to zip or archive files from an absolute directory. If you shift them to another machine, you have no choice but to overwrite those corresponding files on another machine (e.g. it already has a user1 and you are now setting up for somebody who has to be user5). With a relative base like home/ you can choose to unload into /, but you can also unzip into /home/sandbox/.. and mv the dir1, dir2 levels when you know what you are dealing with. Commented Apr 29, 2020 at 10:06
  • I decided instead to maintain individual zip files each containing one directory and transfer those individually using the -d flag. I still need to add the directories to the zip file one at a time, so might as well add them to separate zip files to ensure I don't overwrite anything by mistake and giving me more control where they will end up when I extract them. Thank you!
    – AnthonyBB
    Commented Apr 29, 2020 at 15:30

You must log in to answer this question.

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