When a script file edited under Win is uploaded to the Linux server, it cannot be executed normally. It was mistakenly identified as a Linux configuration problem and later found that, it is caused by different line breaks during Windows and Linux storage files. The linefeed used in DOS is ^ m $, which is called the CR and LF symbols. In Linux, only the LF ($) line break is available.
You can use the following command to convert the format: $ dos2unix and $ unix2dos. However, these two commands do not exist in the Ubuntu release version. You can run the following command:
$ Sudo apt-Get install tofrodos
Command to install. Then, use the following format again.
[Root @ Linux ~] # Dos2unix [-Kn] File [newfile]
[Root @ Linux ~] # Unix2dos [-Kn] File [newfile]
Parameters:
-K: Retain the original mtime format of the file (the last modification time of the file content is not updated)
-N: Retain the original file and output the converted content to the new file, for example, dos2unix-n old New
Example:
Example 1: update the provided hosts file format to DOS format.
[Root @ Linux ~] # Unix2dos-K hosts
Unix2dos: Converting file hosts to DOS format...
# At this time, the hosts file time will not change, but the content mainly changes the line break to the dos crlf.
Example 2: Change "hosts" in the DOS format to hosts. Dos and convert it to Linux
Format to hosts. Linux
[Root @ Linux ~] # Mv hosts. Dos
[Root @ Linux ~] # Dos2unix-K-n hosts. Dos hosts. Linux
Dos2unix: Converting file hosts. DOS to file hosts. Linux in UNIX format...
[Root @ Linux ~] # Ll
-RW-r -- 1 Root 288 Aug 1 13:30 hosts. Dos
-RW ------- 1 Root 279 Aug 1 :30 hosts. Linux
# Because the DOS format contains more Cr characters, the file size is relatively large.