0

I want to use Windows line endings (CRLF) for all of my source files but sometimes Linux line endings get mixed in, e.g. when Git is not properly configured.

How can I easily find all text files which have Linux line endings (LF)?

1 Answer 1

1

A well readable solution using Cygwin is:

 find . -not -path '*/.*' -type f | xargs file | grep text | grep -v CRLF

Explanation:

  • -not -path '*/.*': Filter out all directories starting with . (e.g. .git and .vs)
  • -type f: Consider only files (not directories)
  • xargs file: Apply file command to determine the file type
  • grep text: Only consider text files (file includes string text for all of them)
  • grep -v CRLF: Filter out files with Windows line ending

Note: To find all files with Windows line endings, just remove the -v:

find . -not -path '*/.*' -type f | xargs file | grep text | grep CRLF
2
  • Doesn't "grep CRLF" just grep for the string "CRLF"?
    – pitseeker
    Commented Jul 22, 2020 at 8:08
  • 1
    Yes, that is what file outputs for files with Windows line endings and will thus return all "CRLF" files. Commented Jul 22, 2020 at 8:12

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