3

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:

dir1/subDir1/
dir2/subDir2/
dir3/subDir3/subSubDir3/

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.

2 Answers 2

5

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/
1
  • 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 Sep 24, 2018 at 10:24
5

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

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

--strip-components=NUMBER

strip NUMBER leading components from file names on extraction
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .