データがないフォルダを消すために空にディレクトリを列挙したい。使うと思って作ったディレクトリだったり、ファイルを動かして空のディレクトリをまとめて消したい
空のディレクトリ作業の邪魔だから消したい
find で空ディレクトリを列挙して、xargs で消す*1
空のディレクトリを列挙するには
find -type d -empty
消すにはXargsと組み合わせ
xargsと組み合わせる
find -type d -empty | xargs -I@ rm -rf @
-emptyオプションと -type オプションは
man find によると
-empty File is empty and is either a regular file or a directory. -type c File is of type c: d directory f regular file
ということ type -f で ファイル列挙 type -d でディレクトリ列挙
xargs好き
- execオプション使っても良いけれど、用途別に 分けてコピペできるのでXargsを使ってます。
*1:find の-execでもいいけど