Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a bunch of PHP scripts that are in DOS format (vi displayed [noeol] [dos] in the status line) and as expected they weren't usable.

I ran dos2unix over them to fix the line endins:

dos2unix index.php

but when I open the files in vi I still see [noeol] on the status line.

Upon checking them in vi's hex editor mode (:%!xxd) I don't see anything that jumps out at me.

In the original files the line ends looked like: 0x0D 0x0A

If after running through dos2unix they look like: 0x0A

I also checked to ensure that the last line of the file has a proper end of line and that's there too (0x0A).

What else could be causing this, should I worry?

I'm running CentOS 5.6 x64.

share|improve this question
up vote 5 down vote accepted

As @Klox said, after running dos2unix, the remaining problem vi shows is the missing newline on the last line.

If you open the file in vi and save it, it will add the newline for you.

Or in a batch you can do the whole thing with ed:

for f in <list-of-files-goes-here>; do
    ed -s -- "$f" <<<$',s/\r//g\nw' >/dev/null
share|improve this answer
Thanks, I knocked up a variation in that. Is dos2unix broken? – Kev Aug 25 '11 at 15:29
@Kev: i don't know, i consider it an un-useful tool, given many other methods exist to do the same, without installing nothing new. – enzotib Aug 25 '11 at 15:50
I eventually did: vi +":w ++ff=unix" +":q" ${f} in a loop. – Kev Aug 25 '11 at 15:52

It is just warning you that you don't have an end of line (\n) on the last line.

share|improve this answer
That was the first thing I checked and it's there. – Kev Aug 25 '11 at 13:56
@Kev: when you save, vi insert the last line newline. Have you checked after saving? – enzotib Aug 25 '11 at 14:04
Yes that works as does :set ff=unix, but I have over 200 files and wanted to batch convert them. – Kev Aug 25 '11 at 14:10
Use a shell for loop to run echo >> myfile on each file. – Klox Aug 25 '11 at 15:14

DOS machines enter a carriage return at the end of lines (eol), it should look like this in vi ^M.

Try running this:

share|improve this answer

You may also use ed to batch convert your php files since ed will add the missing final newlines for you as well.

Using ed there is no need for tmp files either.

# using Bash
for file in *.php; do
   ed -s "$file" <<< $'H\n,g/\r*$/s///\nwq'
   #printf '%s\n' H $',g/\r*$/s///' wq | ed -s "$file"
share|improve this answer
I would point out that I came to almost the same solution without seeing your answer :) – enzotib Aug 25 '11 at 15:51

If you use vim (instead of an old skool vi), you can do this:

:set ff=dos

and you'll be able to edit the PHP files without all the ugly "^M" suffixes. I believe it will save as a DOS "text file" format, too. This can be useful if you share the files with (ugh!) Windows somehow.

A little editorializing: the two-byte end-of-line token chosed for MS-DOS has got to have been one of the biggest problems that MS-DOS foisted off on the world, after segments, drive-letters and "\" as directory seperator. That two-byte token is still the reason for a difference between "text" and "binary". Ickk.

share|improve this answer

try this

find . -type f | xargs -I {} dos2unix {}

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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