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)?
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 typegrep text
: Only consider text files (file
includes string text
for all of them)grep -v CRLF
: Filter out files with Windows line endingNote: To find all files with Windows line endings, just remove the -v
:
find . -not -path '*/.*' -type f | xargs file | grep text | grep CRLF
file
outputs for files with Windows line endings and will thus return all "CRLF" files.
Commented
Jul 22, 2020 at 8:12