Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using the command

ls -a | grep '^\.'

for showing only the hidden files. I added the line

alias hidden='ls -a | grep '^\.'' # show only hidden files

to .bash_aliases file

but this does not work. It's probably the problem with ' character.

Could you please help me write the correct alias (and possible rename the title for this question)?

share|improve this question
up vote 19 down vote accepted

Either make the inner pair of quotes double quotes:

alias hidden='ls -a | grep "^\."'

Or make the outer pair of quotes double quotes:

alias hidden="ls -a | grep '^\.'"

Or make all quotes double quotes and escape the inner pair:

alias hidden="ls -a | grep \"^\.\""

Or make it a function, so you can pass some arguments when calling:

hidden() { ls -a "$@" | grep '^\.'; }
share|improve this answer
None of the above works. It shows nothing. – Qualtar Demix Sep 10 '15 at 8:36

Have the shell list the dot files, and tell ls not to see through directories:

ls -d .*
share|improve this answer
This has the advantage of allowing multi-column listing, unlike the grep-based approach. – anol Oct 12 '14 at 13:17
ls -Ad .* #This will list all the hidden files & directories while retaining the color & formatting


To create an alias of the same:

alias lh='ls -Ad .*'


Same thing could be done via grep command and pipe operator; however it would loose the color and formatting:

ls -a|grep "^\." 


Via alias:

alias lh='ls -a|grep "^\."'
share|improve this answer

You can use double quotes:

alias hidden="ls -a | grep '^\.'"

or concatenate more single quoted strings

alias hidden='ls -a | grep '\''^\.'\'

or remove at all internal quotes

alias hidden='ls -a | grep ^\\.'
share|improve this answer

For the record this doesn't seem to work with me, since ls -a prints two (sometimes more columns). I would recommend using the -1 option to make sure every file is in its own line. Something like this:

alias hidden='ls -a1 | grep "^\."'
share|improve this answer
I just tried ls -a | cat it still outputs on 2 columns. I should mention I'm using Solaris and not the GNU ls. Maybe that's why. In all cases your -1 solution worked perfectly and is much more elegant than my hackish workaround. I'm updating my answer. – rahmu Sep 28 '11 at 18:53
I probably missed this discussion, but look here if something will go wrong. – xralf Sep 28 '11 at 19:31

Does your ls support -A? From man ls:

    -a, --all
          do not ignore entries starting with .

   -A, --almost-all
          do not list implied . and ..

$ ls --version
ls (GNU coreutils) 8.5
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  
Written by Richard M. Stallman and David MacKenzie.
share|improve this answer
Yes, it does, but I wanted only hidden files. – xralf Sep 29 '11 at 6:44
ls -A -1 -d -F .* | egrep -v '/$' – waltinator Sep 30 '11 at 21:01

Your Answer


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.