Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

3 Answers 3

up vote 3 down vote accepted

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)

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

Maybe

find . | xargs 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
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
1  
Note that -printf is specific to GNU find. –  Gilles Dec 15 '10 at 8:20

Your Answer

 
discard

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.