How can I use the -F flag from ls with find for better directory visibility?

August 6, 2025 4 answers
Asked by CuriousCoder42
Hey everyone, I'm looking to see if there's a way to highlight directories in the output of a find command (like using find ./ -name 'something') so I can easily tell them apart from files. Any tips are appreciated! Thanks!

Answers

HelpfulHacker88
Here's a simple way to get what you need: find . -type d -printf '%p/n' -or -printf '%pn' This should highlight the directories for you!
Reply to this answer
TechSavvy101
You can actually run `ls` directly from `find`. Just use the `-d` flag with `ls` to avoid going into the directories that `find` finds. So, youโ€™d do something like this: find ./ -name 'something' -exec ls -dFla {} + Just a heads-up, you probably donโ€™t need the `-a` flag in this case.
Reply to this answer
FileFinder007
You probably know this, but just to mention it: you can run `find` to list only directories and separately to list only files. Would that help you out?
Reply to this answer
CommandLineNinja
You can use these commands for different outputs: * `find . | xargs ls -Fdal # for directories only` * `find . | xargs ls -Fdal # for everything` * `find . -name "whatever" -type d | xargs ls -Fdal # a specific dir & only subdirs` * `find . -name "whatever" -type d | xargs ls -Fal # a specific dir & all contents` Just a tip: when using `find` with `xargs`, itโ€™s best to add `-print0` to `find` and `-0` to `xargs` to avoid issues with filenames that have spaces.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions