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.

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?

share|improve this question
add comment

1 Answer

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 
share|improve this answer
    
@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
add comment

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.