How to remove ^M characters at the end of lines in Vi from files in Linux?

Files created in windows when moved to linux will have ^M character at the end of lines when you open the files in Vi editor.

To remove the strange characters open the file in Vi editor and type


This will search for the ^M pattern on the entire file and will remove all occurences.

Other option is to open the file with the strange characters and use the following search and replace pattern


In the above command you need to press ctrl+v and ctrl+m in order for you to get the character ^M in the vi editor

Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Written by kurinchilamp

Website: http://

Leave a Reply

Your email address will not be published. Required fields are marked *

Read previous post:
How to determine the file system type in Linux?

Linux supports many file system types like Ext2, Ext3, Ext4, NFS, FAT16, FAT32, NTFS etc. To find out what type...