Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 tweak the output of ls in Linux so that it looks like the output of the command dir /b /s in Windows?

dir /b /s output as follows:

C:\MinGW>dir /s /b 
share|improve this question

migrated from Jul 4 '10 at 20:23

This question came from our site for professional and enthusiast programmers.

find . -print

This should produce the same output as dir /s/b

share|improve this answer
Not quite. The paths are displayed relative to ., not /. find BACKTICKpwdBACKTICK -print would work. But that's a bit more complicated than just using ls and I don't think exact conformance to dir's output format is a strict requirement. – sepp2k Jul 4 '10 at 20:33
@sepp2k: Given your last sentence, I'm confused why you point out the first. Find is a generally much more useful tool than ls for cases similar to this. – Roger Pate Jul 4 '10 at 23:29
@jrtokarz: You don't need the dot or -print, they're the default, so just "find". – Roger Pate Jul 4 '10 at 23:30
@Roger: I believe the search path is required in most find versions (except GNU). – grawity Jul 5 '10 at 10:19

ls -R lists all files and subdirectories recursively. With ls -R1 you get the same, but only one file per line.

Neither makes the output look exactly like that of dir /b /s, but it should be close enough.

share|improve this answer
ls -1


ls -1d "$PWD"/*
share|improve this answer
/S is the dir equivalent of -R even if the OP's example output does not make that clear. – sepp2k Jul 4 '10 at 20:27
ls -1 does not work recursively (as required). ls -1R would work recursively, but its output will look quite different to dir /s /b (which shows the absolute paths for each file). ls -1d "${PWD}/* also misses two things: the recursion and matching normal files (your -d limits output to directories only). – – Kurt Pfeifle Jul 5 '10 at 13:22

It depends, how hard the requirement is to get "equivalence" to dir /b /s... These ones come pretty close (they'll have no backslashes as directory separator though, and the output order will be a bit different [dir /b /s outputs 'sibling' directories first, before diving into each one to show their content]). The second one is just a fallback in case your version find doesn't default to -print action (most do though):

find $(pwd)
find $(pwd) -print

UPDATE: I had a typo in above commands originally. I typed curly brackets "{}" instead of round ones "()" how they ought to be. Thanks to grawity for spotting this.

share|improve this answer
It's $PWD, uppercase. – grawity Jul 5 '10 at 10:20
@grawity: you're right and wrong at the same time. $PWD or ${PWD} would return the content of an environment variable (the current directory). This is what you have in mind. pwd is a little commandline utility ('print working directory') which also outputs the current directory path. Using it as ${pwd} or as `pwd` would return the result of that command, which in this case has the same effect as using $PWD. So my version will definitely work, and your comment was not appropriate in this context. – Kurt Pfeifle Jul 5 '10 at 10:33
Correction: $(pwd) returns output of pwd, and ${pwd} returns the value of $pwd. Notice the difference in brackets. – grawity Jul 5 '10 at 10:43
@grawity: D'oh! You're right of course. (I do it right whenever I need to do it in a shell. Heaven knows why I did it wrong when typing it into the text edit field....) I'll correct my comments so it will not confuse other readers. – Kurt Pfeifle Jul 5 '10 at 13:13

this seems to work, from the command line:

find|awk "/^\.\//{print\"$PWD\"substr(\$0,2)}"
share|improve this answer
Why would you not just use -printf instead? – Ignacio Vazquez-Abrams Oct 30 '10 at 10:13
Because I'm new and do things the hard way. I've added this line to my .bashrc which seems to do the trick: alias lsb='find . -printf "$PWD/%P\n"' Is this what you mean? Thanks for the tip! – erik Oct 30 '10 at 20:02

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.