Wednesday, July 24, 2013

deleting only directory not files - How to delete only directories and leave files untouched

The following commands deleting only directories (no matter if the directories have anything in it or not, it just deletes all)
make sure you are within the directory: cd into your directory.The simple way:

rm -r */
Another way:
run the following to make sure the output looks fine:
find /path -d -type d
then run:
find /path -d -type d -exec rm -rf '{}' \;
-type d looks only for directories, then -d makes sure to put child directories before the parent.
deleting only directory not files


directory - How to delete only directories and leave files untouched
Remove only files in directory on linux NOT directories
rm directories only, not files, when doing rm -rf

No comments:

Post a Comment