LoginSignup
0
0

tarの--strip-components 1でうまく最上位のディレクトリを取り除けなくて悩んだ

Posted at

アーカイブ内にディレクトリが1つある形でアーカイブしたときに--strip-components 1でそのディレクトリ配下を展開することがあると思います。

その際にディレクトリそのものが展開されてしまい悩んだのでその時の原因と解決法のメモ。

原因

アーカイブされたディレクトリのパスが ./で始まっていた。

↓testディレクトリを取り除いてhogeが展開されてほしい。

$ tar -tf test.tar
./test/
./test/hoge
$ mkdir a
$ tar -C a -xf test.tar --strip-components 1
$ ls a
test

解決法

--strip-components 2とする

$ mkdir b
$ tar -C b -xf test.tar --strip-components 2
$ ls b
hoge

or

./を含まない形でアーカイブする

$ tar cf test2.tar test
$ tar -tf test2.tar
test/
test/hoge
$ mkdir c
$ tar -C c -xf test2.tar --strip-components 1
$ ls c
hoge

それはそうという感じの内容だけどこれで数十分悩んだ:innocent:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0