The Linux Newbie Guide  ⇒    Fundamentals     Advanced     Supplement   Command Index   ENG⇒中
All rights reserved, please indicate the source when citing
 




The dos2unix command in Linux is used to convert text files from the DOS/Windows format to the Unix/Linux format. Text files created or edited on Windows systems often have a different line-ending character sequence compared to Unix/Linux systems. In Windows, lines are terminated by a combination of both a "carriage return" (CR or \r) and a "line feed" (LF or \n), commonly referred to as "CRLF." In Unix/Linux, lines are terminated only by the line feed character.

The dos2unix command helps in converting these Windows-style line endings to Unix-style line endings, making the file compatible with Unix/Linux systems. The basic syntax of the dos2unix command is:
dos2unix [OPTIONS] iFILE .


Here, "OPTIONS" are optional flags that modify the behavior of the dos2unix command, and file is the name of the text file you want to convert.

Some common options for the dos2unix command include:

Here's an example of using the dos2unix command:
dos2unix textfile.txt .

In this example, the dos2unix command converts the line endings in "textfile.txt" from Windows-style to Unix-style.

The dos2unix command is especially useful when working with text files that need to be processed or compiled on Unix/Linux systems, as these systems expect the Unix-style line endings.

Some distributions might not have this tool installed by default. You can achieve the dos2unix functionality using the command tr -d '\r' < DOS_FILE > UNIX_FILE, which removes the "CR" characters to convert from DOS to Unix format.

For further explanation of dos2unix, you can refer to the provided link