Skip to content

Listing just dot-files

Its a problem that I’ve come across, and I’m not the only one, so heres what works for me to find those pesky files that start with a .
ls -a | egrep -i "^\."

This only works in the current working directory, which is the normal usage.

FYI the reason that this is problematic is that the ‘.’ symbol is a single character wildcard; most people are familiar with theĀ asteriskĀ ’*’ indicating ‘anything, however long’, whereas the ‘.’ means ‘any single character’.

The command works by looking only at the first character of the file (‘^’, thats called a caret) and then removing the special meaning of ‘.’ by escaping it with the slash.

Update:18/4/10
@stevebiscuit correctly pointed out that the -i flag is unnecessary.

-iinstructs egrep to ignore the case of any matches, so that ‘HeLlO’ matches if you egrep -i for ‘hello’. Since there is no case for the ‘.’ symbol, the -i is pointless.

{ 2 } Comments

  1. Steven Wilkin | 2010/04/18 at 12:26 | Permalink

    If you’re using egrep the -i flag shouldn’t be necessary… This has the same effect:

    ls -a | egrep ‘^\.’

  2. Bolster | 2010/04/18 at 12:55 | Permalink

    Good point; I’m just in the habit of using egrep -i unconsciously. Thanks!

Post a Comment

Your email is never published nor shared. Required fields are marked *