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
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.
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?
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.
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
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically