親フォルダを削除せずにサブフォルダを削除する

親フォルダを削除せずにサブフォルダを削除する

このタイプのディレクトリ構造の場合:

/config/filegroups/filegroupA/files/fileA1.txt
/config/filegroups/filegroupA/files/fileA2.txt
/config/filegroups/filegroupB/files/fileB1.txt
/config/filegroups/filegroupB/files/fileB2.txt
...

rm -rf /config/filesgroups親フォルダとすべてのサブフォルダを削除するために使用できることがわかります。

/filegroupAしかし、削除するの/filegroupBではなく、などを削除したいと思います。/config/filegroups

ベストアンサー1

rm -rf /config/filegroups/*

ファイルを変更せずにディレクトリ(およびディレクトリへのシンボリックリンク)のみを削除したい場合は、/config/filegroups後でスラッシュを使用できます。

rm -rf /config/filegroups/*/

名前がaで始まるディレクトリを削除するには、.かなり新しいbashがあるとし、dotglobシェルオプションを使用する必要があります。

shopt -s dotglob
rm -rf /config/filegroups/*/
shopt -u dotglob

おすすめ記事