
NLP に関するプロジェクトでは、Project Gutenberg ライブラリのコピーが必要です。現在、プロジェクトでは、特にミラーリング目的であればファイルのダウンロードが許可されています (最終的には設定する予定です)。しかし、私の作業では、存在するファイルの特定のサブセットのみが必要です。
ソースのディレクトリは次のように構成されています。
|
| - 1 - |
| |- 1
| |- 2
| |...
| - 2
| .
| .
| .
| - 9
| - cache
| - retired
| ...
私が関心のあるディレクトリは番号付きのものだけであり、私が関心のあるファイル タイプは だけです。また、または.txt
で終わるファイルも不要ですが、今のところは許容するつもりです。-8.txt
-h.txt
これまで試したこと:
--include "*/" --include "*.txt" --exclude "cache" --exclude "images" --exclude "retired" --exclude "pg" --exclude "*-8.txt" --exclude "*"
.txt
<- このフォルダにもいくつかのファイルが含まれているため、"cache" フォルダも引き続き取得されます。--include "*/" --include "*.txt" -f'- *\-8.txt' -f'- *\-h.txt' -f'- cache/**' --exclude "cache" --exclude "images" --exclude "retired" --exclude "pg" --exclude "*"
<- ほぼ同じもの
問題は次のようになります:
- 除外する必要があるすべて必要なものは極めて限られているので
- 必要なのは番号付きディレクトリだけなので、番号付きディレクトリを含めます
- 他のディレクトリにもテキスト ファイルが含まれているため、含めると
*.txt
以前の除外が解除されます。
これについてどうしたらいいでしょうか?
答え1
投稿から rsync - いくつかを除くすべてのディレクトリを除外するから引用します 回答者:ダリル・E・クラーク:
単純なフィルターで十分でしょう。適切な例を使って前の回答を構築するには、親とすべての (**) サブフォルダーとファイルを明示的に含めます。次に、その他すべてを除外します。次のようになります
filter.txt
。+ /include_this_dir/ + /include_this_dir/** + /include_that_dir/ + /include_that_dir/** - /** With the command line: rsync -av --dry-run --filter="merge filter.txt" source_dir/ dest_dir/
結果は次のようになります:
sending incremental file list created directory dest_dir ./ include_that_dir/ include_that_dir/somefile.txt include_that_dir/subdir/ include_this_dir/ sent 202 bytes received 65 bytes 534.00 bytes/sec total size is 0 speedup is 0.00 (DRY RUN)
これに のフィルターを追加します*.txt
。
つまり、最初にすべてを含め、次にすべてを除外します。
答え2
番号付きディレクトリを glob で明示的に一致させることができます[0-9]/
:
-f'+ [0-9]/' \
-f'- *-[8h].txt' \
-f'+ *.txt' \
-f'- *' \
数字が 9 を超える場合は、-f'+ [0-9][0-9]/
または を追加すれば-f'+ [0-9]*/
十分でしょう。