Take the 2-minute tour ×

I want to list all the directories that start with . in the current directory. I don't want the previous directory (..) to be listed so I had the regular expression something like this. I am using csh

ls .[^.]*

It works fine on UNIX variant platforms but in solaris, I am still using the csh but it lists me only .. directory. How can I specify the regular expression with the exact functionality in Solaris. It works in bash but I have to use csh only as it is guaranteed to be available on each SOLARIS box in our org.

share|improve this question
grymoire.com/Unix/CshTop10.txt HTH. I can't imagine why a bourne shell wouldn't be on all of your solaris boxes. –  Will Hartung Sep 21 '11 at 5:12
Confirmed on Solaris 9. I'd suggest using tcsh instead, but if you can't count on bash I suppose you can't count on tcsh. Incidentally, that's a file matching pattern, not a regular expression. I think grep, as mu is too short suggested, is your best bet. –  Keith Thompson Sep 21 '11 at 5:21
add comment

3 Answers

up vote 2 down vote accepted

You can do this with /bin/sh, but with a slightly different syntax; it uses ! rather than ^ to negate the set of characters:

ls .[!.]*

Note that this is a file matching pattern (a glob), not a regular expression.

But given the variations you're seeing in the glob syntax supported by various shells, you might be better off using grep with actual regular expressions.

share|improve this answer
add comment

Character classes in globs in csh don't support negation...

From the man page in Solaris:

       is  two  characters  separated  by  a  dash  (-),  and
       includes  all  the  characters in between in the ASCII
       collating sequence (see ascii(5)).

So... you could create a character class that includes a range from \040 (space) to '-' (the character before '.', then from '/' to '~' (the remaining printable ascii characters).

ls -a .[\ --/-~]*

This seems to work for me, but I haven't checked the output with a fine-toothed comb.

share|improve this answer
add comment

csh? Wow, I didn't know they still made that :) Your ls .[^.]* works on OSX's csh so I don't know what's going on with the Solaris csh. A crufty backup would be something like this:

ls `ls -a | grep '^\.[^.].*'`

The -a for ls tells it to include all the dot-files in the list and then a bit of grep for dealing with the dots. That matches what ls .[^.]* does in OSX's csh, hopefully it will work with Solaris's as well.

share|improve this answer
add comment

Your Answer


