ls's -F flag allows to see the types of file and distinguish directories. Is there a way to add a functionality to distinguish an empty directory?


This can't be done with ls (at least, as far as I am aware), but you can find empty directories using find:

find . -type d -empty

If the depth matters to you, with GNU find:

find . -maxdepth 1 -type d -empty 
  • @Prometheus. If you need detailed view you may try ls -ial `find . -maxdepth 1 -type d -empty` – sundeep Mar 26 '13 at 6:15
  • 1
    @sundeep - Parsing the output of find like that will break on whitespace, I wouldn't recommend it. – Chris Down Mar 26 '13 at 6:24
  • I suppose I have to glue them together? I know this may be complicated, but is there a way for me to modify the output of ls and then pipe it to another program that will highlight differently? I am thinking of awk to replace the match by find and then use grep to highlight the output, but I do not know how the syntax highlighting is implemented in bash and grep does not match the directory name. Also grep will erase the highlight done by ls. Would you happen to know how to get around these problems? – Forethinker Mar 26 '13 at 17:10

Just in case, to find the non-empty ones:

find . -mindepth 1 -maxdepth 1 -not -empty -type d

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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