How do I extract files inside a directory from a tar file in terminal?
cd <another_directory>
tar xvf <path_to_tar>/<tarfile>.tar <child_dir>
for examplecd <parent_directory>
tar cvf test.tar *
tar tf test.tar
see the folder you want. for examplesrc/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
a source to share
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
.
a source to share