LoginSignup
3
6

More than 1 year has passed since last update.

並列化で高速に大量ファイルの削除,転送.xargとか

Last updated at Posted at 2021-02-16

ファイル一括消去

ワイルドカードでは対応不可能なくらい大量のファイル

$ find ./ -name "*.txt" -exec rm -fv {} \;

-execオプションを使えばfmコマンドに渡すことができる.
こっちは逐次繰り返しrm実行

$ find ./ -name "*.txt" | xargs rm -fv

こっちは一括rm実行。
並列処理すると高速に実行できる。

$ find ./ -name "*.txt" | xargs -P 8 rm -fv

自分の環境では並列数8で頭打ちとなった。

image.png

ファイル転送コピー

特定のディレクトリを除外

rsync -av --exclude="data/"  ./foge/    ./fuga/

オプションでフィルターを掛けるとよけいなファイルをコピーしない.
fogeというディレクトリを除外した

高速化xargs

$ echo "./hoge" | xargs -P4 -i% rsync -av --progress % ./fuga 

まとめ

ファイル高速転送

$ echo "./hoge/" | xargs -P4 -i% rsync -av --exclude="1/"  --progress % ./fuga

-p オプション 進捗状況表示
-e オプション 除外ファイル,ディレクトリ
-i オプション 含めるファイル,ディレクトリ

-P4 オプション 4並列する
-i% オプション %に引数./hogeを代入

3
6
1

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
3
6