Remove subfolder with specific name in linux

Remove subfolder with specific name in linux

Remove specific subfolder in linux

Sometimes it happens that you just have to delete a subfolder that is duplicated in multiple folders.

You can also go folder by folder and try rm -rf folder_name or you can just use find, exec and then rm, like so:

find -type d -name node_modules -exec rm -rf {} \;

I’ve used find -type d because the name used for searching is a folder meaning that we don’t care about other files with `node_modules` name. find -type d -name node_modules node_modules is the folder that needs to be deleted and by doing so we need to execute a command in that context and we are taking advantage of: -exec rm -rf {} \; which will execute a command for every file that matches our search.

Share This:

Related Posts