Session and utilities

The unix2dos command

Converts the line endings of a file from Unix (LF) to Windows (CRLF), which uses a carriage return and a line feed. Useful to deliver text to Windows programs that reject LF. It is common when preparing files for Windows or for older programs that expect CRLF.

Syntax

unix2dos [opciones] archivo...Try it in the terminal →

Most useful options

-n ENTRADA SALIDAWrites the result to a new file and leaves the original untouched
-mAdds a UTF-8 byte order mark (BOM) at the start of the file
-qQuiet mode: suppresses the warnings

Copy-ready examples

$ unix2dos informe.txtconverts the file in place. It changes the original.

Example output

unix2dos: converting file informe.txt to DOS format...
$ unix2dos -n notas.txt notas_windows.txtcreates a copy with CRLF and leaves notas.txt as it was.

Example output

unix2dos: converting file notas.txt to file notas_windows.txt in DOS format...
$ unix2dos -m datos.csvadds a BOM so Excel recognizes the UTF-8 when it opens the CSV.

Example output

unix2dos: converting file datos.csv to DOS format...

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
unix2dos: nonexist: No such file or directoryThe file does not exist or the name is misspelled.Check the name with ls and try again.
unix2dos: Skipping carpeta, not a regular file.You gave a directory. unix2dos only converts regular files.Name the files one by one or loop over the directory.
unix2dos: Skipping binary file bin.datThe file is binary, such as an image or a PDF. unix2dos skips it to avoid damaging it.Convert only text. If it really is text, check why it is detected as binary.

Typical mistakes

  • It overwrites the original by default. Use -n if you need to keep it.
  • A script with a BOM may stop running, because the shebang is no longer the first byte.
  • Binary files are skipped for safety. Use -f only when you are sure the file is text.
  • A file converted to CRLF looks fine on Windows, but a Linux script with CRLF breaks: do not mix it with the Unix flow.

Differences from similar commands

  • dos2unix: does the opposite: it converts CRLF to LF.
  • file: shows which line endings a file has, for example CRLF. Use it before converting to know what you have.
  • sed: can add the carriage return with a single expression, but it does not protect binary files or handle the BOM.

Related commands

FAQ

When do I need unix2dos?

When a Windows program, such as the classic Notepad, displays files with only LF incorrectly.

Does unix2dos add a BOM by default?

No. It only adds one with -m, and then it writes the bytes EF BB BF at the start of the file. Without a BOM, some Windows programs misread accented letters.

Can I convert without touching the original?

Yes. With -n, unix2dos input.txt output.txt writes the result to a new file.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course