Ubuntu: tar -xvzf [filename] creates an extra directory



Question:

I have a tar file in /var/www/orbitcode/public_html/orbit.tar.gz when I unzip it using tar -xvzf orbit.tar.gz a new pub_html directory is created.

The path of the extracted files is /var/www/orbitcode/public_html/public_html/[extracted files].

Shouldn't the extracted files be in the orbit directory? Why is it creating a new public_html directory?

I am using ubuntu 14.04.


Solution:1

When you created /var/www/orbitcode/public_html/orbit.tar.gz you missed the message that told you

tar: Removing leading `/' from member names  

Use tar tf /var/www/orbitcode/public_html/orbit.tar.gz to list the member names.

To correct for the current situation (use sudo to taste),

cd /var/www/orbitcode/public_html  # Assume extracted files must replace current dir files  mv -v -f --target-directory=$PWD public_html/* public_html/.*  # rmdir FAILS on non-empty directories  rmdir public_html  


Solution:2

It happens presumably because you tarred the whole public_html directory and its name is in the archive.

You can use the --strip-components argument to cut off the head of the path when extracting.

In your case:

tar -xvzf --strip-components 1 orbit.tar.gz  

To remove the public_html/ and extract files directly into the current directory.

1 in the above command stands for a single level in the extracted path.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »