newbie
newbie

Reputation: 767

how to tar without the parent directory but with the last directory

I am trying to tar a directory without the parent directories and I have found a solution so far which removes the parent directories and tar all the files under a directory called (DIR) to a DIR.tar.gz file using the following:

tar -cvzf $DIR.tar.gz -C $path/$DIR .

But if I want to untar the tared file, it will untar all the files in the current directory, however, I want to be able to tar the dir in a way which when I use tar -xzvf, it will untar it into folder called DIR. IT should be simple, but I am not able to find the solution on the net. Any hint?

Upvotes: 4

Views: 4695

Answers (1)

Kel Cecil
Kel Cecil

Reputation: 194

I believe what you want is:

tar -cvzf $DIR.tar.gz -C $path ./$DIR

This should change the directory to your folder path (-C) and only include the relative directory ($DIR) that you're trying to archive.

Upvotes: 7

Related Questions