🍋
Menu
Troubleshooting Beginner 1 min read 186 words

Troubleshooting Line Ending Issues (CRLF vs LF)

Different operating systems use different line endings, causing text files to display incorrectly or break scripts. Learn how to detect and fix the issue.

Key Takeaways

  • Windows uses CRLF (\r\n), Unix/macOS uses LF (\n), and old Mac Classic used CR (\r).
  • Text appears as one long line (LF file opened on old Windows software).
  • Look for `^M` characters at line ends in terminal editors.
  • Convert CRLF to LF for Unix/macOS use.
  • Configure Git to handle line endings consistently: `git config core.autocrlf true` on Windows, `git config core.autocrlf input` on macOS/Linux.

The Line Ending Problem

Windows uses CRLF (\r\n), Unix/macOS uses LF (\n), and old Mac Classic used CR (\r). When files move between systems, line endings can cause rendering problems and break scripts.

Symptoms

  • Text appears as one long line (LF file opened on old Windows software).
  • Extra blank lines appear between every line (CRLF on some Unix viewers).
  • Shell scripts fail with \r: command not found errors.
  • Git shows every line as changed despite no content modifications.

Detection

Look for ^M characters at line ends in terminal editors. In a hex editor, CRLF shows as 0D 0A and LF shows as 0A. Many text editors show line endings in the status bar.

Fixing Line Endings

Convert CRLF to LF for Unix/macOS use. Convert LF to CRLF for Windows batch scripts. Most modern editors handle this automatically, but bulk conversion tools are needed for large file collections.

Git Configuration

Configure Git to handle line endings consistently: git config core.autocrlf true on Windows, git config core.autocrlf input on macOS/Linux. A .gitattributes file can enforce settings per file type.

Verwandte Tools

Verwandte Formate

Verwandte Anleitungen