# man > dos2unix(1)

---
type: CommandReference
command: dos2unix
mode: man
section: 1
source: man-pages
---

## Quick Reference

- `dos2unix path/to/file` — Change DOS line endings to Unix
- `dos2unix -n path/to/file path/to/new_file` — Create a copy with Unix line endings
- `dos2unix -i path/to/file` — Display file information
- `dos2unix --keep-bom path/to/file` — Keep Byte Order Mark
- `dos2unix --add-bom path/to/file` — Add Byte Order Mark
- `dos2unix --remove-bom path/to/file` — Remove Byte Order Mark
- `unix2dos path/to/file` — Convert Unix to DOS line endings
- `mac2unix path/to/file` — Convert Mac (CR) to Unix line endings

## Name

DOS/Mac to Unix and vice versa text file format converter

## Synopsis

shell
dos2unix [options] [FILE ...] [-n INFILE OUTFILE ...]
unix2dos [options] [FILE ...] [-n INFILE OUTFILE ...]
## Options

### Conversion Modes

- `-c, --convmode CONVMODE` — Set conversion mode: `ascii` (default, line breaks only), `7bit` (strip non-ASCII), `iso` (DOS charset to ISO-8859-1), `mac` (Mac line breaks)
- `-ascii` — Convert only line breaks (default)
- `-iso` — Convert between DOS code page and ISO-8859-1
- `-7` — 7-bit conversion
- `-1252`, `-437`, `-850`, `-860`, `-863`, `-865` — Force specific DOS code page for ISO conversion

### Input/Output and File Handling

- `-o, --oldfile FILE ...` — Convert in-place (default mode)
- `-n, --newfile INFILE OUTFILE ...` — Convert to new file (paired mode)
- `-k, --keepdate` — Preserve original file timestamp
- `-f, --force` — Force conversion of binary files
- `-s, --safe` — Skip binary files (default)
- `--allow-chown` — Allow file ownership change in old file mode
- `--no-allow-chown` — Abort if ownership cannot be preserved (default)
- `-F, --follow-symlink` — Convert target of symbolic link
- `-R, --replace-symlink` — Replace symbolic link with converted file
- `-S, --skip-symlink` — Keep symbolic links unchanged (default)

### Byte Order Mark (BOM)

- `-b, --keep-bom` — Write BOM if input had one
- `-r, --remove-bom` — Remove BOM from output
- `-m, --add-bom` — Add UTF-8 BOM (or UTF-16 if input is UTF-16)

### Unicode

- `-u, --keep-utf16` — Keep original UTF-16 encoding (no conversion to UTF-8)
- `-ul, --assume-utf16le` — Assume input is UTF-16LE
- `-ub, --assume-utf16be` — Assume input is UTF-16BE

### Information and Diagnostics

- `-i[FLAGS], --info[=FLAGS] FILE ...` — Display file information (line break counts, BOM, text/binary). Flags: `0` null-separated, `d` DOS breaks, `u` Unix breaks, `m` Mac breaks, `b` BOM, `t` text/binary, `c` list convertible files, `h` header, `p` strip path
- `-D, --display-enc ENCODING` — Set display encoding for Windows (ansi, unicode, unicodebom, utf8, utf8bom)
- `-q, --quiet` — Suppress warnings and messages
- `-v, --verbose` — Show extra info (BOM, line break counts)
- `-h, --help` — Display help
- `-V, --version` — Show version
- `-L, --license` — Show license

### Other

- `-l, --newline` — Double each line break (add extra newline)
- `-gb, --gb18030` — Convert UTF-16 to GB18030 (Windows only)
- `--` — Treat all following arguments as file names

## Examples

### Basic Conversion

shell
# Convert and replace file
dos2unix a.txt

# Convert from stdin to stdout
dos2unix < a.txt

# Create new file with Unix line endings
dos2unix -n a.txt e.txt

# Convert multiple files
dos2unix a.txt b.txt
### Keep Timestamp

shell
dos2unix -k a.txt
### Mac Mode

shell
dos2unix -c mac a.txt
mac2unix a.txt
### BOM Handling

shell
# Remove BOM when converting to Unix
unix2dos -r a.txt

# Add UTF-8 BOM
dos2unix -m -n in.txt out.txt
### File Information

shell
# Show line break info for all .txt files
dos2unix -i *.txt

# List files with DOS line breaks
dos2unix -ic *.txt

# Convert only files with DOS line breaks
dos2unix -ic0 *.txt | xargs -0 dos2unix
### Recursive Conversion

shell
# Unix shell (find + xargs)
find . -name '*.txt' -print0 | xargs -0 dos2unix

# Windows Command Prompt
for /R %G in (*.txt) do dos2unix "%G"

# PowerShell
get-childitem -path . -filter '*.txt' -recurse | foreach-object {dos2unix $_.Fullname}
## See Also

- [file](https://www.chedong.com/phpMan.php/man/file/1/markdown)
- [find](https://www.chedong.com/phpMan.php/man/find/1/markdown)
- [iconv](https://www.chedong.com/phpMan.php/man/iconv/1/markdown)
- [locale](https://www.chedong.com/phpMan.php/man/locale/1/markdown)
- [xargs](https://www.chedong.com/phpMan.php/man/xargs/1/markdown)

## Exit Codes

- `0` — Success (also in quiet mode except for invalid options)
- System error code — On system error (last system error returned)
- `1` — Other errors (e.g., conversion failure, invalid options)