I know how to extract single file from a tarball, although now I have 500 GB tar file without any compression, just a plain tar and I would like to extract specifically 3 directories, with such structure:


There are many subdirectories inside each of those and real many files. I wish to simply extract everything inside of those.

I am curious as to how to do this, without having to extract the whole tarball.


tar extracts directories like files, see the man page for more info.

# -v; verbose parameter is rather obstructive
#     in case of thousands and thousands of files

tar -xf archive.tar directory/
  • 3
    I have tested and tar -xvzf keys/ssl/nginx/ssl-0.0.0-development.tgz -C keys/ssl/nginx package/ dit extract a directory named package within keys/ssl/nginx. That does not work, the root of the tar is still extracted with this synthax – Dimitri Kopriwa Sep 24 '18 at 10:24

You can use the --strip-components=n option.

tar -xvf archive.tar --strip-components=4


strip NUMBER leading components from file names on extraction

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.