LinuxCommandLibrary

dos2unix

TLDR

Convert file line endings

$ dos2unix [path/to/file]
copy
Create copy with Unix line endings
$ dos2unix -n [path/to/file] [path/to/new_file]
copy
Display file information
$ dos2unix -i [path/to/file]
copy
Handle BOM (keep/add/remove)
$ dos2unix --[keep-bom|add-bom|remove-bom] [path/to/file]
copy

SYNOPSIS

dos2unix [options] [file...]

DESCRIPTION

dos2unix converts text files from DOS/Windows format (CRLF line endings) to Unix format (LF line endings). It modifies files in place by default.
Essential when working with files created on Windows or transferred between operating systems.

PARAMETERS

-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)

CAVEATS

Modifies files in place by default; use -n to preserve original. Binary files may be corrupted. Check with -i before converting.

SEE ALSO

unix2dos(1), unix2mac(1), file(1)

Copied to clipboard