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?

  • 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
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.

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 .
  • 2
    or simply find The default expression is . – user4556274 Feb 17 '17 at 18:58
  • 3
    True. Anyway I think it is a good practice to include defaults in Q/A posts, as they might not be obvious to everyone. – Bruno9779 Feb 17 '17 at 19:00
  • 19
    @user4556274 It may be for GNU find, but other implementations follow the POSIX standard and requires a directory operand. – Kusalananda Feb 17 '17 at 19:21
5

tree -if

-i to not indent -f to print path

  • 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 linux.die.net/man/1/tree – Stephen C Feb 17 '17 at 23:27
  • 1
    It's from mama.indstate.edu/users/ice/tree, and packaged as tree in a number of Linux distributions. – deltab Feb 18 '17 at 1: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)"
  • 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. – a CVn 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. – a CVn Feb 19 '17 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.