Forensicstext-conversionline-endingsdosunixmac

dos2unix

dos2unix converts text file line endings between DOS (CRLF), Unix (LF), and Mac (CR) formats. It includes utilities like unix2dos, mac2unix, and unix2mac for bidirectional conversion.

Description

This package contains utilities dos2unix, unix2dos, mac2unix, and unix2mac to convert the line endings of text files between UNIX (LF), DOS (CRLF), and Mac (CR) formats. Text files under Windows and DOS typically have two ASCII characters at the end of each line: CR (carriage return) followed by LF (line feed). Older Macs used just CR, while UNIX uses just LF. While most modern editors can read all these formats, there may still be a need to convert files between them.

This is the classic utility developed in 1989. It is useful in scenarios where file compatibility issues arise due to differing line ending conventions across operating systems. The tools support in-place conversion or new file output using the -n option.

How It Works

The tools convert line endings by replacing CRLF (DOS) with LF (Unix), CR (Mac) with LF (Unix), or vice versa. They handle character set conversions like DOS to ISO-8859-1 with specific code pages (e.g., -1252 for Windows, -437 for US DOS). Options allow keeping or removing Byte Order Marks and controlling file ownership changes.

Installation

bash
sudo apt install dos2unix

Flags

--allow-chownallow file ownership change
-asciidefault conversion mode
-isoconversion between DOS and ISO-8859-1 character set
-1252use Windows code page 1252 (Western European)
-437use DOS code page 437 (US) (default)
-850use DOS code page 850 (Western European)
-860use DOS code page 860 (Portuguese)
-863use DOS code page 863 (French Canadian)
-b, --keep-bomkeep Byte Order Mark (default)
-r, --remove-bomremove Byte Order Mark

Examples

converting file unix.txt to file dos.txt in DOS format
unix2dos -n unix.txt dos.txt
converting file unix.txt to file mac.txt in Mac format
unix2mac -n unix.txt mac.txt
converting file dos.txt to file unix2.txt in Unix format
dos2unix -n dos.txt unix2.txt
converting file mac.txt to file unix3.txt in Unix format
mac2unix -n mac.txt unix3.txt
display help for dos2unix
dos2unix -h
display help for mac2unix
mac2unix -h
display help for unix2dos
unix2dos -h
display help for unix2mac
unix2mac -h
Updated 2026-04-16kali.org ↗