I want to extract only the files inside a folder of a tar file
Example:
Contents of tar file:
/home/parent_dir/child_dir/
I want to extract only the files inside child_dir to another directory
Now, if you want a single file or folder from the “tar” file, you need to use the name of the “tar” file and the path to a single file in it. So, we have used the “tar” command with the “-xvf” option, the name of the “tar” file, and the path of a file to be extracted from it as below.
To extract (unzip) a tar.gz file simply right-click on the file you want to extract and select “Extract”. Windows users will need a tool named 7zip to extract tar.gz files. The -v option will make the tar command more visible and print the names of the files being extracted on the terminal.
The 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
is not where you want them to be, GNU tar provides a --transform
option that would be used like:
tar --transform 's,/home/parent_dir/child_dir,foo,' --show-transformed -xf tarfile.tar
which will put the files that would have gone into /home/parent_dir/child_dir
into ./foo
instead.
cd <another_directory>
tar xvf <path_to_tar>/<tarfile>.tar <child_dir>
e.g.cd <parent_directory>
tar cvf test.tar *
tar tf test.tar
see the folder you wanted. e.g.src/org
cd <some other directory you want to extract to>
tar xvf ..\test.tar src/org
ls
you'll now see the directory you were after from the tar e.g.src/org
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With