Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find dos format files in a linux file system

I would like to find out which of my files in a directory are dos text files (as opposed to unix text files).

What I've tried:

find . -name "*.php" | xargs grep ^M -l

It's not giving me reliable results... so I'm looking for a better alternative.

Any suggestions, ideas?

Thanks

Clarification

In addition to what I've said above, the problem is that i have a bunch of dos files with no ^M characters in them (hence my note about reliability).

The way i currently determine whether a file is dos or not is through Vim, where at the bottom it says:

"filename.php" [dos] [noeol]
like image 283
denormalizer Avatar asked Jan 18 '11 01:01

denormalizer


People also ask

How can you tell if a file is in DOS or Unix?

If file reports "CRLF line terminators", the file is DOS-style. If file reports "CR line terminators", the file is Mac-style. If file doesn't mention line terminators, the file is Unix-style.

What is DOS format in Linux?

DOS format uses "carriage return" (CR or \r ) then "line feed" (LF or \n ). Mac format uses "carriage return" (CR or \r ) Unix uses "line feed" (LF or \n )

What is DOS file format?

(1) A computer file created by an application running under the DOS operating system. See DOS. (2) A text file. See ASCII file.


1 Answers

How about:

find . -name "*.php" | xargs file | grep "CRLF"

I don't think it is reliable to try and use ^M to try and find the files.

like image 86
bvpb Avatar answered Sep 20 '22 08:09

bvpb