Deleting Files with find

Jul 29, 2021 · 1 min. read

Sometimes a program creates dot files within a project that I don't want to add to git or upload to a server. Once I notice them, I'll try to find the setting that prevents them from being created, but I'm still left with a bunch of files I don't want. find makes it easy to find and delete these files.

For example, I can find all the .DS_Store files generated on my Mac with:

find . -name ".DS_Store*"

Deleting the files is as simple as adding the -delete flag:

find . -name ".DS_Store*" -delete

I recommend always testing your find statement without the -delete flag, then adding it if the results match what you'd like to delete.