How do I find all files that end with a "." (dot) and then delete them? Is there a program that can do this?


Desktop DB. mp600osxpd542ej7.

  • find -name *. -delete maybe – guiverc Mar 23 at 21:56
  • I would to list the files first so that I don't delete something that I want to keep. – Kathryn Trucano Mar 23 at 22:03
  • I would never run a command like that first time with a -delete option; run it without the delete so it just finds the files, and you can peruse the files it will delete, then only when happy add the -delete option). find finds files by name, date, permissions or anything, but you can also tell it to execute something for each file, delete them etc. It's a standard *nix command from 1978 – guiverc Mar 23 at 22:05
  • Do you need this to delete plain files only - or directories as well? does it need to be recursive or just files at one directory level? – steeldriver Mar 23 at 22:23

The following cmd will do:

find . -type f -name '*.' -exec rm -i {} \;

cmd explanation:

  • find: the utility we used to search for files and perform actions on them.
  • -type f:that makes sure that we find files only
  • -name '*.': that tells find to pick up files with names that match the pattern, which has a wildcard *, that matches any number of characters, followed by the dot we're looking for.
    note that we quoted the pattern, this is important to avoid the expansion of the wildcard by the shell.
  • -exec: that tells find to perform the following action on the files that have been found.
  • rm -i {}: the cmd rm -i removes files interactively, which means that it will ask you any time, it wants to delete a file, that's a good option if you want to check your files one by one before deletion, otherwise you can omit the option -i.
    the curly braces are placeholders for the files found by find.
  • finally we end the command executed by find with an escaped semicolon \;

find -name "*." -delete

find will locate files named pattern '*.' (ie. end in a dot) & delete them. The use of -delete also implies -depth too, but adjust to your needs.

Quotes added as I'd forgotten, thanks @steeldriver

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.