海馬のかわり

最近記憶力に難がある、地方在住サーバエンジニアの備忘録です。

tarで圧縮、展開の一括処理

tarコマンドを使い、ファイルやディレクトリ単位で一括圧縮/展開処理する場合のメモ


・複数ファイルを、個別に圧縮する

$ ls test*
testfile001  testfile002  testfile003  testfile004  testfile005
$ 
$ ls test* | xargs -n1 -i tar cvzf {}.tar.gz {}
testfile001
testfile002
testfile003
testfile004
testfile005
$ 
$ ls *.tar.gz
testfile001.tar.gz  testfile003.tar.gz  testfile005.tar.gz
testfile002.tar.gz  testfile004.tar.gz


・複数のアーカイヴを一括展開する

$ ls
testfile001.tar.gz  testfile003.tar.gz  testfile005.tar.gz
testfile002.tar.gz  testfile004.tar.gz
$ 
$ ls *.tar.gz | xargs -n1 tar xvzf
testfile001
testfile002
testfile003
testfile004
testfile005
$ 
$ ls
testfile001         testfile002.tar.gz  testfile004         testfile005.tar.gz
testfile001.tar.gz  testfile003         testfile004.tar.gz
testfile002         testfile003.tar.gz  testfile005


・複数のアーカイヴを指定のディレクトリに一括展開する

$ mkdir /tmp/hoge
$ ls
testfile001.tar.gz  testfile003.tar.gz  testfile005.tar.gz
testfile002.tar.gz  testfile004.tar.gz
$ 
$ ls *.tar.gz | xargs -n1 -i tar xvzf {} -C /tmp/hoge
testfile001
testfile002
testfile003
testfile004
testfile005
$
$ ls /tmp/hoge
testfile001  testfile002  testfile003  testfile004  testfile005

以上