Find Command – Make Find Show Slash After Directories

find

How can I make the find command show a slash after directories? For example, I want dir to show up as dir/ instead of dir. I'm using find . -print

Best Answer

Portably:

find . -type d -exec sh -c 'printf "%s/\n" "$0"' {} \; -or -print

If you're willing to list directories and files separately (you can merge the output by sorting):

{ find . -type d -print | sed 's!$!/!'; find . \! -type d; } | sort

With GNU find, see Shawn J. Goff's answer.

If you're willing to risk non-printable characters being mangled even when not outputting to a terminal, see ddeimeke's answer.

In zsh: print -rl -- **/*(DM) (D to include dot files, M to add a / after directories)

Related Question