Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 5 down vote accepted


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)

share|improve this answer
+1 for "in zsh" – xenoterracide Dec 15 '10 at 13:15
The first command didn't print trailing slashes for me, but the second one does. – Steven Dec 16 '10 at 17:45
find . \( -type d -printf "%p/\n" , -type f -print \)

This uses the printf command to format directory names and standard print for the rest.

share|improve this answer
+1 clever use of find's arcane option processing – msw Dec 15 '10 at 3:58
I continue to be amazed at the flexibility of find. – Shawn J. Goff Dec 15 '10 at 4:12
Note that -printf is specific to GNU find. – Gilles Dec 15 '10 at 8:20


find . -print0 | xargs -0 ls -Fd

is an option as well.

From a Solaris man page:

-F Marks directories with a trailing slash (/), doors with a trailing greater-than sign (>), executable files with a trailing asterisk (*), FIFOs with a trailing vertical bar (|), symbolic links with a trailing "at" sign (@), and AF_UNIX address family sockets with a trailingequals sign (=). Follows symlinks named as operands.

share|improve this answer
@Gilles: Thanks for the "d" ;-) – ddeimeke Dec 15 '10 at 12:40

Your Answer


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.