Search code examples
windowsbashcygwinls

Exact Bash equivalent for CMD dir /b


In the Windows command prompt, dir /b > List.txt prints a linebreak-separated list of the contents of a directory to a text file:

Folder 1
Folder 2
Folder 3
File 1.txt
File 2.txt
File 3.txt

In bash on Cygwin, doing ls > File.txt produces the following:

Folder 1Folder 2Folder 3File 1.txtFile 1.txtFile 2.txt

Bash doesn't seem to default to printing entries on their own line, and neither ls -h nor ls -1 seem to make any difference to this. Also, seeing the -a option makes me worried about what results are being shown - do I need to call -a to see all of the results that would ordinarily be shown using dir /b in CMD, or simply to see those that I wouldn't have seen in CMD?

How do I do the exact equivalent of dir \b in Bash?


Solution

  • redirecting output of ls to File.txtwill result of one file per line. thus, your command is correct. you can verify this on bash using cat File.txt.

    probably, you are viewing the output file on notepad. please view it on notepad++ and you will see it is correct.