dos2unix Commands – Removing Hidden Windows Characters from Files

Posted on by Matt Aurand | Updated:
Reading Time: < 1 minute

While editing files on a machine running some form of Windows and uploading them to a Linux server is convenient, it can cause unforeseen complications. Windows-based text editors put special characters at the end of lines to denote a line return or newline. Normally harmless, some applications on a Linux server cannot understand these characters and can cause the service to not respond correctly. There is a simple way to correct this problem: dos2unix.

What do the hidden characters look like?

Below is an example from a php.ini file showing what the hidden characters look like:

;;;;;;;;;;;;;;;;;;;^M
; Resource Limits ;^M
;;;;;;;;;;;;;;;;;;;^M
;^M
max_execution_time = 30^M
max_input_time = 60^M
memory_limit = 32M^M

As said before, these characters will not appear in most Windows text editors, but will appear in Linux command line utilities like cat or vi. Removing them is rather painless. Just run the command dos2unix.

root@host [~]# dos2unix /path/to/file

In the above example of the php.ini, it will look something like this:

root@host [~]# dos2unix /usr/local/lib/php.ini
dos2unix: converting file /usr/local/lib/php.ini to UNIX format ...

That’s it. If the command has worked correctly, the file in question shouldn’t have any of the hidden characters in it, like the following:

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;
;
max_execution_time = 30
max_input_time = 60
memory_limit = 32M

The dos2unix command is a simple way to make sure that files that have been edited and uploaded from a Windows machine to a Linux machine work and behave correctly. If you are uncomfortable running this command yourself or have any questions or concerns, please give our Heroic Support a call.

Avatar for Matt Aurand

About the Author: Matt Aurand

Latest Articles

How to use kill commands in Linux

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change the root password in WebHost Manager (WHM)

Read Article