dos2unix Commands – Removing Hidden Windows Characters from Files
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.
Related Articles:
About the Author: Matt Aurand
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Latest Articles
How to Edit the PHP Memory for Your WordPress Site via WP Toolkit
Read ArticleWhat is CGI-Bin and What Does it Do?
Read ArticleTop 10 Password Security Standards
Read ArticleTop 10 Password Security Standards
Read ArticleHow to Use the WP Toolkit to Secure and Update WordPress
Read Article