Ubuntu find and delete files and directories/folders
There is often the time when you need to find some files in a certain directory/folder and delete them. One such example is cleaning out the .svn directories/folders from a copy (when you should’ve done an export).
First build your find command, for finding .svn directories/folders:
find ./ -d -name .svn
Verify that the find command produces the expected results. This is that extra insurance so you don’t accidentally delete something you didn’t mean to.
Once you’ve got your find command, simply add the delete option:
find ./ -type d -name .svn -delete
Another such example is removing the .swp files from vim.
find ./ -type f -name *.swp -delete
You might notice there are many other posts about this very subject. Most of these posts are older, and don’t take advantage of the newer find option of delete. Instead, you will find them use the typical rm -rf, which we all know can get nasty if one is not careful.
Leave a Reply