nishimura.clubnishimura.club

シェルで特定のディレクトリを削除する

作成日
2022-11-10
更新日
2022-11-10

既存のディレクトリ配下から__snapshots__というディレクトリを見つけ、ディレクトリごと削除するコマンド

find . -type d -name "__snapshots__" -print0 | xargs -0 -I {} /bin/rm -rf "{}"

参考

試行錯誤の記録(見ないで)

find ./component -mindepth 3 ! -regex '^./component/__snapshots__\(/.*\)?' find ./component -mindepth 3 ! -regex '^./component/__snapshots__\(/.*\)?' # __snapshots__の中身のみを削除 find ./component -mindepth 3 ! -regex '^./component/__snapshots__\(/.*\)?' -delete find ./component -mindepth 3 ! -regex '^./component/__snapshots__\(/.*\)?' -empty -delete find ./component -mindepth 3 ! -regex '^./component/__snapshots__\(/.*\)?' -exec rm -f {} # __snapshots__dirを削除 find ./component -maxdepth 3 -type d ! -iname __snapshots__ -exec rm -rvf {} \; ls component/ | grep -v "__snapshots__" | xargs rm -r find . -type d -iname "__snapshots__" | xargs rm -r find . -type d -name "__snapshots__" -print0 | xargs -0 -I {} /bin/rm -rf "{}"

Related

Tags

シェル

Share