[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

Advertisements

[Linux command] display tar content with level and without extracting

 
The command allows display the content of a tar file without extracting, and with –exclude option which uses the pattern can also show the level you want to display.

Example :

tar --exclude="*/*/*" -tf yout_tar_file.tar.gz