I'm working on Linux and there is a folder, which contains lots of sub directories. I need to delete all of sub directories which have a same name. For example,
dir
|---subdir1
|---subdir2
| |-----subdir1
|---file
I want to delete all of subdir1
. Here is my script:
find dir -type d -name "subdir1" | while read directory ; do
rm -rf $directory
done
However, I execute it but it seems that nothing happens.
I've tried also find dir -type d "subdir1" -delete
, but still, nothing happens.
find dir -type d -name "subdir1"
list the folders properly? – Ornate--delete
to-delete
. – Michalrm -rf dir/subdir1
to remove one of them and it works. I don't need to dosudo
. – Antilles