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

后端 未结 9 1231
栀梦
栀梦 2020-11-30 17:24

I want to search for files containing DOS line endings with grep on Linux. Something like this:

grep -IUr --color \'\\         


        
9条回答
  •  萌比男神i
    2020-11-30 18:03

    Use Ctrl+V, Ctrl+M to enter a literal Carriage Return character into your grep string. So:

    grep -IUr --color "^M"
    

    will work - if the ^M there is a literal CR that you input as I suggested.

    If you want the list of files, you want to add the -l option as well.

    Explanation

    • -I ignore binary files
    • -U prevents grep from stripping CR characters. By default it does this it if it decides it's a text file.
    • -r read all files under each directory recursively.

提交回复
热议问题