tar を使用してパターンのあるディレクトリを再帰的に除外する

tar を使用してパターンのあるディレクトリを再帰的に除外する

tarを使用してアーカイブしたいさまざまなPythonパッケージを含むディレクトリがあります。__pycache__ビルド/テストプロセスから残された多数のフォルダを除外する必要があります--exclude "__pycache__"。このパターンに一致するすべてのサブディレクトリを無視するようにtarにどのように指示できますか?

tar -cvf myarchive.tar -C ~/myproject package1/ package2/ --exclude "__pycache__"

再構築:

me@me-laptop:~/myproject$ pwd
/home/me/myproject
me@me-laptop:~/myproject$ tree
.
├── package1
│   ├── include
│   └── __pycache__
└── package2
    ├── include
    └── __pycache__

6 directories, 0 files
me@me-laptop:~/myproject$ tar -cvf myarchive.tar -C ~/myproject package1/ package2/ --exclude "__pycache__"
package1/
package1/include/
package1/__pycache__/
package2/
package2/include/
package2/__pycache__/

ベストアンサー1

--excludeコマンドの先頭にスイッチを追加する必要があります。これ。このソリューションは私のopenSUSEコンピュータで動作しますが、現在利用可能な他のディストリビューションはありません。

host:/tmp # find test*
test1
test1/file1
test1/__pycache__
test1/__pycache__/file1-py
test1/include
test1/include/file1-incl
test2
test2/__pycache__
test2/__pycache__/file2-py
test2/include
test2/include/file2-incl
test2/file2

host: # tar --exclude='__pycache__' -cv test* -f testtar.tar
test1/
test1/file1
test1/include/
test1/include/file1-incl
test2/
test2/include/
test2/include/file2-incl
test2/file2

おすすめ記事