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
C:\MinGW\COPYING
C:\MinGW\COPYING.LIB
C:\MinGW\doc
C:\MinGW\include
find . -print
This should produce the same output as dir /s/b
.
, 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.
find
versions (except GNU).
Jul 5, 2010 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.
ls -1
or
ls -1d "$PWD"/*
/S
is the dir equivalent of -R
even if the OP's example output does not make that clear.
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). –
Jul 5, 2010 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.
$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.
Jul 5, 2010 at 10:33
$(pwd)
returns output of pwd
, and ${pwd}
returns the value of $pwd
. Notice the difference in brackets.
Jul 5, 2010 at 10:43
this seems to work, from the command line:
find|awk "/^\.\//{print\"$PWD\"substr(\$0,2)}"
.bashrc
which seems to do the trick: alias lsb='find . -printf "$PWD/%P\n"'
Is this what you mean? Thanks for the tip!