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

0
1
Asked By CuriousCoder42 On

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!

4 Answers

Answered By CommandLineNinja On

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.

Answered By FileFinder007 On

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?

Answered By TechSavvy101 On

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.

Answered By HelpfulHacker88 On

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!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.