How to delete only directories and leave files untouched
find . -maxdepth 1 -mindepth 1 -type d
then
find . -maxdepth 1 -mindepth 1 -type d -exec rm -rf '{}' \;
To add an explanation:
find
starts in the current directory due to .
and stays within the current directory only with -maxdepth
and -mindepth
both set to 1
. -type d
tells find
to only match on things that are directories.
find
also has an -exec
flag that can pass its results to another function, in this case rm
. the '{}' \;
is the way these results are passed. See this answer for a more complete explanation of what {}
and \;
do