Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When I do ls -l | grep ^d it lists only directories in the current directory.

What I'd like to know is what does the caret ^ in ^d mean?

share|improve this question
    
For related information, look up regular expressions or check out this page on using regular expressions in grep: robelle.com/smugbook/regexpr.html –  Trey Hunner Oct 14 '10 at 3:51

2 Answers 2

up vote 17 down vote accepted

Andy's answer is correct, as seen in the man page:

Anchoring

The caret ^ and the dollar sign $ are meta-characters that respectively match the empty string at the beginning and end of a line.

The reason it works is the -l flag to ls makes it use the long-listing format. The first thing shown in each line is the human-readable permissions for the file, and the first character of that is either d for a directory or - for a file

share|improve this answer

That's a caret, not a carrot. It means "beginning of the line." The grep is matching only lines that start with "d".

share|improve this answer
    
Thanks for the correction! –  Glide Oct 14 '10 at 8:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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