if I run the following command in my mac terminal:

ls -al | grep ^\. 


ls -al | grep '^\.' 


ls -al | grep "^\." 

I get no results back even though there are several files in my home directory that meet this criteria. I tried this in both bash and zsh, and get nothing.

If I run this same command without quotes in Ubuntu, I get the expected results. Can anyone explain why this is?

  • For me, on Debian (bash) and OS X (zsh), ls -al | grep ^\. returns every file in the directory, just like ls -al | grep ^. would. On the other hand, ls -al | grep '^\.' returns nothing for me on either OS. Aug 5, 2020 at 1:17
  • Yes, me too. I forgot about those pulling back all files and folders the point was that none of them work correctly.
    – Paul W
    Aug 5, 2020 at 3:06

2 Answers 2


The grep pattern matches lines that begin with a dot. The output of ls -al has no such lines.

Try ls -a | grep '^\.' and see the difference.

  • On Mac it requires a '\n' or the start of a line, whereas Linux will pick up anything that starts with '.' within the line. Seems odd that it is not the same. Is there some character problem that is breaking it, or is it just designed that way, that is what I am want to find out. ~$ ls -al | grep ^\. total 76 drwxr-xr-x 8 nodejs nodejs 4096 Jul 13 00:47 . drwxr-xr-x 3 root root 4096 Jun 23 20:42 .. -rw-rw-r-- 1 nodejs nodejs 40 Jul 11 05:09 .bash_aliases -rw------- 1 nodejs nodejs 7914 Aug 4 23:00 .bash_history -rw-r--r-- 1 nodejs nodejs 220 Feb 25 12:03 .bash_logout ...
    – Paul W
    Aug 5, 2020 at 2:58

This is pretty lame. earlier today I had deleted some of the files I had on the linux server and forgot. All that was left were config files, example .config.

When I ran the grep it returned everything which were all of the .xxxx files. I thought I still had other files in the directory. That is why I believed it was not working correctly. So this is really a non question, just a mistake on my part.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .