← 返回命令列表

Linux command

dos2unix 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Convert

dos2unix [path/to/file]

Example

dos2unix -n [path/to/file] [path/to/new_file]

Example

dos2unix -i [path/to/file]

Example

dos2unix --[keep-bom|add-bom|remove-bom] [path/to/file]

说明

dos2unix converts text files from DOS/Windows format (CRLF line endings) to Unix format (LF line endings). DOS/Windows systems use carriage return and line feed (\\r\\n) to mark line endings, while Unix-like systems use only line feed (\\n). Line ending mismatches cause problems in scripts, compilation errors, or rendering issues in text editors. This tool resolves these issues by normalizing line endings to the Unix standard. It handles byte order marks (BOM) commonly found in UTF-8 files from Windows. The tool operates in-place by default, modifying the original file, but can create new output files preserving the original. It intelligently detects file formats and can provide information about a file's current line ending format before conversion.

参数

-n, --newfile _in_ _out_
Write to new file instead of in-place
-i, --info _flags_
Display file information
--keep-bom
Keep Byte Order Mark
--add-bom
Add Byte Order Mark
--remove-bom
Remove Byte Order Mark
-c, --convmode _mode_
Conversion mode (ascii, 7bit, iso)

FAQ

What is the dos2unix command used for?

dos2unix converts text files from DOS/Windows format (CRLF line endings) to Unix format (LF line endings). DOS/Windows systems use carriage return and line feed (\\r\\n) to mark line endings, while Unix-like systems use only line feed (\\n). Line ending mismatches cause problems in scripts, compilation errors, or rendering issues in text editors. This tool resolves these issues by normalizing line endings to the Unix standard. It handles byte order marks (BOM) commonly found in UTF-8 files from Windows. The tool operates in-place by default, modifying the original file, but can create new output files preserving the original. It intelligently detects file formats and can provide information about a file's current line ending format before conversion.

How do I run a basic dos2unix example?

Run `dos2unix [path/to/file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -n, --newfile _in_ _out_ do in dos2unix?

Write to new file instead of in-place