ディレクトリと同じ名前のアーカイブにディレクトリをtarしますか?

ディレクトリと同じ名前のアーカイブにディレクトリをtarしますか?

ディレクトリ全体を圧縮/保存し、後で削除するエレガントな方法はありますか?これまで私は大きな解決策を思いつきました。

から:

# ls -la
drwxr-xr-x 3 root root 4096 Jul  4 15:01 .
drwxr-xr-x 6 root root 4096 Jul  4 14:54 ..
drwxr-xr-x 4 root root 4096 Jul  4 14:59 stresstest

到着する:

# ls -la
drwxr-xr-x 3 root root 4096 Jul  4 15:01 .
drwxr-xr-x 6 root root 4096 Jul  4 14:54 ..
drwxr-xr-x 4 root root 4096 Jul  4 14:59 stresstest.tar.gz

編集#1

問題は、ディレクトリの名前を事前に知ることができないことです(動的に生成されるため、次回は異なる場合があります)。ただし、ここでは常にディレクトリ名が唯一のディレクトリになります。

ベストアンサー1

$ for i in *;do tar zcvf ${i}.tgz $i; rm -fr $i;done

はい

$ for i in *;do tar zcvf ${i}.tgz $i; rm -fr $i;done
stresstest/
stresstest/file1
stresstest/file2
stresstest/file3

$ ll
total 4
-rw-r--r-- 1 root root 162 Jul  5 05:18 stresstest.tgz

おすすめ記事