Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 have a directory that contains thousands of files, some of them are hidden.

The command ls -a list all files, including hidden ones, but I need just to list hidden files.

What command should I use?

share|improve this question

10 Answers 10

up vote 47 down vote accepted

The command :

ls -ld .?* 

Will only list hidden files .

Explain :

 -l     use a long listing format

 -d, --directory
              list  directory entries instead of contents, and do not derefer‐
              ence symbolic links

.?* will only state hidden files 
share|improve this answer
You don't need the two question marks in there, the * covers it ( ? only matches any single character, * matches any number of them ). – psusi May 19 '14 at 0:50
@psusi, I think the intent is to exclude . and .. from the match. However it will also exclude (perfectly legal) single-character hidden filenames such as .a, .1 and so on. Perhaps a better extended glob would be .!(|.) i.e. literal dot followed by anything except nothing or another (single) dot i.e. ls -d .!(|.) – steeldriver May 19 '14 at 1:25
@steeldriver you should write an answer with that command. – Lucio May 19 '14 at 1:27
Sorry about the double rollback, I was confused. – terdon May 19 '14 at 2:56
@steeldriver, neat, the ?? version does exclude "." and "..". This seems to be the result of an interesting quirk: neither ? nor * will match a dot, but the ? must match something otherwise the name is ignored. – psusi May 19 '14 at 3:37
ls -d .!(|.)

Does exactly what OP is looking for .

share|improve this answer

If you just want the files in your current directory (no recursion), you could do

echo .[^.]*

That will print the names of all files whose name starts with a . and is followed by one or more non-dot characters. Note that this will fail for files whose name starts with consecutive dots, so for example will not be shown.

You could also use find:

find -mindepth 1 -prune -name '.*'

The -mindepth ensures we don't match . and the -prune means that find won't descend into subdirectories.

share|improve this answer
ls -ad .*

works for me in Bash.

share|improve this answer

Using find and awk,

find . -type f | awk -F"/" '$NF ~ /^\..*$/ {print $NF}'


find . -type f --> List all the files in the current directory along with it's path like,


awk -F"/" '$NF ~ /^\..*$/ {print $NF}'

/ as field separator awk checks for the last field staring with a dot or not. If it starts with a dot, then it prints the last field of that corresponding line.

share|improve this answer
You could just use find -type f. You don't need to explicitly set the search path or -name "*". – terdon May 19 '14 at 3:08
Thanks :D @terdon – Avinash Raj May 19 '14 at 3:10

find is usually a better option for complicated searches than using name globbing.

find . -mindepth 1 -maxdepth 1 -name '.*'


find . -mindepth 1 -maxdepth 1 -name '.*' -o -name '*~'

find . searches current directory

-mindepth 1 excludes . and .. from the list

-maxdepth 1 limits the search to the current directory

-name '.*' find file names that start with a dot

-o or

-name '*~' find file names that end with a tilde (usually, these are backup files from text editing programs)

However, this and all of the other answers miss files that are in the current directory's .hidden file. If you are writing a script, then these lines will read the .hidden file and display the file names of those that exist.

if [[ -f .hidden]] # if '.hidden' exists and is a file
    while read filename # read file name from line
        if [[ -e "$filename" ]] # if the read file name exists
            echo "$filename" # print it
    done < .hidden # read from .hidden file
share|improve this answer
What's the .hidden file? Why would there ever be a file called .hidden that contains the file names? Anyway, if there is one why would you do something that complex when all you would need would be cat .hidden? Your find command is correct(ish) but the -name '*~' is irrelevant. Files that end in tildes are backup files but not hidden in any way. – terdon May 21 '14 at 3:19
@terdon The .hidden file is for files and folders you want to hide when you can't change the file/folder name to start with a dot. As for files that end in tildes, it depends on the system. ls -B will ignore such files, as will most GUI file explorers. – Mark H May 2 at 21:31
cat .hidden may show files that no longer exist if those files were deleted or moved since being added to the .hidden file. – Mark H May 2 at 21:35

You can also use:

ls -d .[!.]* .??*

This will allow you to display normal hidden files and hidden files which begin with 2 or 3 dots for example : ..hidden_file

share|improve this answer
With this I get all hidden files twice. – TuKsn May 19 '14 at 9:02

What else you could have done, is ls .?* Or ls .!(|) that will show you everything in the current dir hidden files/dirs on the top and other files/dirs below

e.g: from my terminal

$ ls .?*       
.bash_history    .dmrc        .macromedia   .weather
.bash_logout     .gksu.lock   .profile      .wgetrc
.bash_profile .ICEauthority .toprc           .Xauthority
.bashrc          .lastdir     .viminfo      .xsession-errors
.bashrc~         .dircolors   .lynxrc       .vimrc           .xsession-errors.old



cache  config

compizconfig-1                              rhythmbox
dconf                                       shotwell

Now notice in the above results, it shows you every file/dir with its subdir and any hidden files right below.

$ ls .!(|)
.bash_aliases  .bashrc1  .bashrc1~

askapache-bash-profile.txt  examples.desktop             Public           top-1m.csv
backups             Firefox_wallpaper.png        PycharmProjects
Desktop             java_error_in_PYCHARM_17581.log  Shotwell Import Log.txt  topsites.txt
Documents           Music                Templates            Videos
Downloads           Pictures                 texput.log           vmware

Sorry, I cannot comment. to explain the difference here between ls .?* and @cioby23 answer ls -d .[!.]* .??* And why it is actually printing hidden files twice is because literally you're asking twice .??*, .?*, .[!.]* they're the same thing, so adding any of them with different command characters will print twice.

share|improve this answer

I think that you can do it with following command.

ls -a | grep "^\." | grep -v "^\.$" | grep -v "^\..$"

ls -a command you entered, that shows all files and directories in current working directory.

grep "^\." command I appended, that filters output to shows only hidden files(It's name starts with ".").

grep -v "^\.$" | grep -v "^\..$" command I appended, that filters output to exclude ., ..(They are current and parent directory).

If some filenames can have more than a line with "\n", above example could be incorrect.

So I suggest following command to solve it issue.

find -maxdepth 1 -name ".[!.]*"
share|improve this answer
You should never parse the output of ls. – Radu Rădeanu May 19 '14 at 8:50
@RaduRădeanu I saw your comment, It's so good. I edited my answer again. Thank you to your comment. – xiaodongjie May 21 '14 at 3:03

you can use the command

ls -Ad .??*

This has the advantage of allowing multi-column listing, unlike the grep-based approach in the ls -a | grep "^\." solutions

share|improve this answer

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.