How do I extract files inside a directory from a tar file in terminal?

I only want to extract files inside tar file folder

Example:

Tar file content:

  • /home/parent_dir/child_dir/

I only want to extract files inside child_dir to another directory

+2


a source to share


2 answers


cd <another_directory>


tar xvf <path_to_tar>/<tarfile>.tar <child_dir>


for example
cd <parent_directory>


tar cvf test.tar *


tar tf test.tar


see the folder you want. for example src/org


cd <some other directory you want to extract to>


tar xvf ..\test.tar src/org


ls


now you will see the directory you used after tar, eg.src/org



+2


a source


Command

tar xf tarfile.tar /home/parent_dir/child_dir

      

will only extract files in child_dir

and its subordinates.



If /home/parent_dir/child_dir

not where you want, GNU tar provides an option --transform

to be used like:

tar  --transform 's,/home/parent_dir/child_dir,foo,' --show-transformed -xf tarfile.tar

      

that will put the files that have moved in /home/parent_dir/child_dir

to ./foo

.

+9


a source







All Articles