HelloWorld_Always
HelloWorld_Always

Reputation: 1565

Eliminate directory hierarchy while tarring

$ tar -zcvf archive/test.tar.gz files

will give me as below:

files/
files/1
files/2
files/3

--

$ tar -zcvf archive/test.tar.gz -C files .

will give me as below :

./
./1
./2
./3

I am not able to figure out the right tar command for an output as below .

1
2
3

Upvotes: 0

Views: 429

Answers (2)

Anya Shenanigans
Anya Shenanigans

Reputation: 94869

You use the --transform option, which takes a sed expression.

--transform="s/^\.\///"

should have the desired effect.

Edit Oops, looks like this will leave a leading './' entry in the tar archive, which is probably not desirable. using @paulsm's answer is probably simpler, but it may miss out on hidden files (files starting with .)

Upvotes: 1

paulsm4
paulsm4

Reputation: 121881

Personally, I'd just:

cd files
tar -zcvf /full-path/archive/test.tar.gz *

Upvotes: 0

Related Questions