tar without root directory at specific directory
When you untar a tar file, it often comes with a directory structure. This is excellent when you are untar-ing the file at the current location
will untar all content, including the directory structure at current location.
There are times when you want to untar the content to a specific directory without the root directory
For example, you have a pre-created directory /install/xyz and you want to untar the content of a tar file without the root directory abc
You can use the command as follow
where
To check if your tar file include a top level directory, you could use
to verify
e.g tar -xzvf hello.tar.gz
will untar all content, including the directory structure at current location.
There are times when you want to untar the content to a specific directory without the root directory
For example, you have a pre-created directory /install/xyz and you want to untar the content of a tar file without the root directory abc
You can use the command as follow
$ tar -xvf /custom_release/abc.tar.gz -C /install/xyz --strip-components=1
where
-C specify the directory
--strip-components=1 will remove the root directory.
To check if your tar file include a top level directory, you could use
tar -tf xyz.tar.gz | head
to verify
Comments
Post a Comment