Install Dos2Unix on Raspberry Pi

Install Dos2Unix on Raspberry Pi

DOS/Windows systems uses different text file line endings than Unix/Linux systems. On DOS/Windows line endings are represented as carriage return followed by line feed (CRLF or \r\n). However, Unix/Linux uses only line feed (LF or \n) for line endings. Dos2Unix is a package that includes dos2unix and unix2dos commands that allows to convert line endings in a text file from DOS/Windows to Unix/Linux and vice versa.

This tutorial demonstrates how to install Dos2Unix on Raspberry Pi.

Connect to Raspberry Pi via SSH. Update the package lists and install Dos2Unix with commands:

sudo apt update
sudo apt install -y dos2unix

After the installation is finished, we can check version:

dos2unix --version
unix2dos --version

Now create a text file that contains CRLF line endings:

printf "First\r\nSecond\r\nThird\r\n" > test.txt

We can use the file command to check the type of line endings:

file test.txt

Output:

test.txt: ASCII text, with CRLF line terminators

Run the dos2unix command to convert line endings from DOS/Windows to Unix/Linux:

dos2unix test.txt

Now we can check again the type of line endings with file command. We will get the following output:

test.txt: ASCII text

There is also opposite command unix2dos that converts line endings from Unix/Linux to DOS/Windows:

unix2dos test.txt

If Dos2Unix is no longer needed, you can remove it with command:

sudo apt purge --autoremove -y dos2unix

Leave a Comment

Cancel reply

Your email address will not be published.