2

I'm new to Linux and I'm currently trying to do the following:

  • unzip the contents of wordpress-4.1.1.zip to the directory in which it is contained which is /my-test-site/wordpress-4.1.1.zip

I understand to unzip I can run this command from within the directory:

unzip wordpress-4.1.1.zip

but that then leaves me with a sub directory called wordpress. I can then go in and run this command from the sub directory in order to move the files up a level:

mv * ../

If I do that I then have all of the wordpress core files in the my-test-site directory which I want. But I'm wondering If I can run the unzip command in such a way that it extracts the contents directly into my-test-site directory and doesnt create a sub directory containing the files?

Thanks

1 Answer 1

2

You can use two command line options to unzip to get your desired result, provided the zip contains no sub directories.

unzip -j -d /my-test-site wordpress-4.1.1.zip

Note that if your zip was of the order:

foo
├── 1
├── 2
├── 3
├── 4
├── 5
├── 6
├── 7
├── 8
├── 9
└── bar
    ├── 1
    ├── 2
    ├── 3
    ├── 4
    ├── 5
    ├── 6
    ├── 7
    ├── 8
    └── 9

Using this option would mean the files contained in foo/bar would clobber (replace the contents of) all files located in foo. I.e, the -j option removes all paths relatives to the file locations in the zip and puts in them in either the current directory (default) or the directory specified by the -d option.

If your zip has sub-directories, your method would be the way to go about extracting that zip file.

You could always alias the command:

alias wp_unzip='mv wordpress-4.1.1.zip /my-test-site && \
    cd /my-test-site && unzip wordpress-4.1.1.zip && \
    mv wordpress/* . && rmdir wordpress'
1
  • Yes you see my issue is that the zip file has a number of sub directories so I guess I'll have to go about it the initial way. Thank you for your helpful answer. It's good to know that this is possible. Commented Mar 11, 2015 at 9:05

You must log in to answer this question.

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