What’s The Buzz

Random posts on what’s happening in the world of Linux and Open Source Technology

Linux Goodies

Linux tips and tricks picked up on the job as a Linux Systems Engineer.

Apple Goodies

All things wonderful about Apple Computers and Devices

Microsoft Goodies

Microsoft System Engineering tips and tricks as told by a Linux Systems Engineer

XKCD

Get your daily dose of the XKCD cartoon

Home » Linux Goodies

How To Delete All Dot Files From a Directory In Linux

Submitted by dkblinux98 on March 6, 2010 – 11:47 amOne Comment



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.

One Comment »

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.

Powered by WP Hashcash