Does WSL use LF line endings or CRLF line endings?

Viewed 2557

Unix uses LF line endings. Windows uses CRLF line endings. What about WSL?

1 Answers

The question doesn't really have an answer, because operating systems don't use line endings, applications use line endings. Most OS APIs provide the contents of a file to an application as a continuous stream of bytes, not a collection of lines, so it is up to the application to read and write line endings according to whatever algorithm it wants.

The convention on Windows (and before that, MS-DOS) was for applications to indicate line endings with a CR LF pair, while the convention on Unix (and related systems such as Linux) was for applications to use just an LF.

Modern applications are generally capable of reading and writing either format - that includes Notepad in up to date versions of Windows - but may pick a default based on these historical conventions.

Since applications running under WSL are the same as they would be running under a real Linux system, they will probably default to LF.

Related