How To Delete All Dot Files From a Directory In Linux

Have you ever typed this rm -rf .* within a directory on Linux and discovered that .* matches the . .. directories and therefore starts deleting much more than you intended? In order to properly delete the dot files within a directory while still preserving the directory itself, try this: rm -rf .[^.]* && rm -rf ..?* What this will do is ensure that the dot file name has at least one character after the dot and the second rm will do the same for file names that begin with two dots.

If you have any other clever ways to tackle this issue, I'd love to hear from you.

Darla Baker

Darla Baker is the author of the Amazon best-selling novel Eagle Cove (Thalia Chase: Sex Therapist Series, Book One). She is the founder of Stone Soup Community, a non-profit press focusing on helping queer writers market their books.

Darla lives with her wife on the shores of beautiful Lake Cumberland, Kentucky during lake season and on the road in her custom campervan, Dulcinea, the rest of the year. Her adorable staffy, Mati, is always by her side.

https://stonesoupcommunity.com
Previous
Previous

The Honeymoon Phase

Next
Next

Bloom Energy Be The Solution