How do you search for files containing DOS line endings (CRLF) with grep on Linux?

grep probably isn’t the tool you want for this. It will print a line for every matching line in every file. Unless you want to, say, run todos 10 times on a 10 line file, grep isn’t the best way to go about it. Using find to run file on every file in the tree then grepping through that for “CRLF” will get you one line of output for each file which has dos style line endings:

find . -not -type d -exec file "{}" ";" | grep CRLF

will get you something like:

./1/dos1.txt: ASCII text, with CRLF line terminators
./2/dos2.txt: ASCII text, with CRLF line terminators
./dos.txt: ASCII text, with CRLF line terminators

Leave a Comment