9

The question What is the Linux equivalent of DOS “dir /s /b filename”? comes close but it winds up playing a file find operation for all such named file names.

I'm however looking to do a directory contents diff comparison with a directory on a Windows machine and compare it to what should be a similarly constructed directory on a QNX box. I want to run the directory enumerating command on both machines, do some text file manipulation to convert path delimiting characters and root drives and what not to get them into a compatible format for an insightful diff.

I can generate a folder manifest of all subdirectories and files therein with dir /b /s, and get output formatted as a bunch of paths...

c:\Temp>dir /b /s
c:\Temp\Subfolder1
C:\Temp\Subfolder1\File1.txt
C:\Temp\Subfolder1\File2.txt
...

I can see dir /s becomes ls -R, but how do I get the /B equivalent of the path output formatting?

jxramos
  • 193
  • 6
    The answer is the same as in the other question, except you leave out the -name option, so it doesn't filter by name. – Barmar Feb 17 '17 at 18:55

4 Answers4

18

There isn't a flag for ls which will do what you ask, but you can accomplish it with several other tools, the easiest being (possibly) find:

find .
Bruno9779
  • 1,384
14

find may give you all that you need. It has a little more overhead as it performs more tests than ls alone, but if you want the path information in the output then this may be the simplest way to achieve that.

If you're going to compare two systems, then you should probably do some text editing first and swap \ with /, and remove the C: prefix. Then sort the lists and use diff to spot the changes. sed will be your friend here. Follow-up with a comment if you want this too.

Ed Neville
  • 1,340
5

tree -if

-i to not indent -f to print path

Guest
  • 51
  • Interesting, show some console output to your answer; I can't find that command from my QNX box -bash: tree: command not found – jxramos Feb 17 '17 at 23:12
  • I'm on my phone so can't test it, but it's in the man page at https://linux.die.net/man/1/tree – Stephen C Feb 17 '17 at 23:27
  • 1
    It's from http://mama.indstate.edu/users/ice/tree/, and packaged as tree in a number of Linux distributions. – deltab Feb 18 '17 at 01:09
  • tree is my tool of choice to inspect directory structure, but it is not installed by default on most systems. – Bruno9779 Feb 20 '17 at 12:47
5

In order to get the actual path prefixed (assuming that's important), do

find "$(pwd)"
wjandrea
  • 658
Joshua
  • 1,893
  • If you are using a bash-like shell, no need to invoke an external command; find "${PWD}" should be enough. Not sure if that works on QNX, though. – user Feb 18 '17 at 14:02
  • @MichaelKjörling: Well if you want the symlink path rather than the real path ... – Joshua Feb 18 '17 at 21:29
  • True, it might depend on the exact semantics of each. Don't forget that at least GNU bash has a built-in pwd as well as the external /bin/pwd, too, which also differ in how they handle directories reached by symlinks. – user Feb 19 '17 at 11:39