[Linux command] Tar – Extract only the contents of an archived directory


As said the subject, we want to extract only the contents of a tar file to a specific folder.

I have my tar : myTarFolder.tar, my destination folder : destFolder

The structure of my tar file :

Image 10

If we use only the tar command, we will get :

tar -xf myTarFolder.tar -C destFolder 

Image 11

If we want to get something like this :

The option that we have to use is :

  1. –strip-components=NUMBER : strip NUMBER leading components from file names on extraction

An example of the command :

tar -xf myTarFolder.tar --strip-components=1 -C destFolder

The result :

Image 12