A line break when modifying a file under Windows causes a problem in Linux to run abnormally

Source: Internet
Author: User
Tags printable characters ftp client

ENV:/etc/init.d/nginx:no such file or directory

Cause: A problem with line breaks when you modify a file under Windows .

line breaks are different under Windows and Linux. The runtime on the general operating system automatically determines the line-wrapping format of the text file. If a program runs on Windows, it generates a text file in CR/LF format, while running on Linux generates a text file with the LF format wrapped. A file file that uses another line break on one platform can cause unexpected problems, especially when editing program code . Sometimes the code appears normal in the editor, but when you edit it, the error occurs because of a line break. Many text/code editors have a newline character conversion feature that allows you to swap line breaks in text files in different formats.

When transferring files between different platforms using FTP software, in ASCII text mode transfer mode, some FTP client programs automatically convert to the line format. The number of file bytes passed through this transfer may vary. If you do not want FTP to modify the original file, you can use bin mode (binary mode) to transfer the text.

Workaround: successfully resolve the issue after using Dos2unix filename conversion once under Linux.

The Dos2unix command is used to convert a DOS-formatted text file into Unix (Dos/mac to UNIX text, format Converter). Dos text file is based on \ r \ n As a break mark, expressed as 16 binary is 0D 0 A. The text file under Unix is marked with \ n as a break mark, which means that the 16 binary is 0 a. The DOS format text file under Linux, with the lower version of VI Open the end of the ^m will be displayed, and many commands are not very good processing of this format of the file, if it is a shell script. The UNIX-formatted text files are displayed together when opened with Notepad under Windows. As a result, there is a need to convert the two format files to each other, and the Unix2dos command that translates the UNIX format text file into a DOS format.
Common parameters:

The simplest way to convert a DOS-formatted text file into a UNIX format is to dos2unix the file name directly.

Format: Dos2unix file

If you convert more than one file at a time, follow these file names directly after Dos2unix. (Note: can also be added to the-o parameter, also can not add, the same effect)

Format: Dos2unix file1 file2 file3

Format: Dos2unix-o file1 file2 file3

The above in the conversion, will be directly on the original file modification, if you want to save the results of the conversion of other files, and the source file is not changed, you can use the-n parameter.

Format: Dos2unix oldfile newfile

If you want to keep the file timestamp constant, add the-K parameter. So the above commands can be added with the-K parameter to keep the file timestamp.

Format: Dos2unix-k file

Format: dos2unix-k file1 file2 file3

Format: dos2unix-k-o file1 file2 file3

Format: dos2unix-k-n oldfile newfile

Note: The Unix2dos command is used in a similar way to the Dos2unix command.
Cat-v can see non-printable characters in the file, and the cat command without the-v parameter does not work.
Hexdump-c can see the hexadecimal representation of each byte of the file.

Cat-v can see non-printable characters in the file, and the cat command without the-v parameter does not work.
Hexdump-c can see the hexadecimal representation of each byte of the file.

Reprinted from: Moon ' s Blog

A line break when modifying a file under Windows causes a problem in Linux to run abnormally

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.