On DOS/Windows systems, different text file line endings are used than on the Unix/Linux systems. DOS/Windows uses line endings that 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 contains dos2unix and unix2dos commands for converting line endings in a text file from DOS/Windows to Unix/Linux and vice versa.
This tutorial shows how to install Dos2Unix on Ubuntu 20.04.
Install Dos2Unix
Execute the following command to update the package lists:
sudo apt update
Next, install Dos2Unix:
sudo apt install -y dos2unix
Once installation is completed, we can check version as follows:
dos2unix --version
unix2dos --version
Testing Dos2Unix
For testing purpose, create a text file that has CRLF line endings:
printf "First\r\nSecond\r\nThird\r\n" > test.txt
The file
command can be used to verify the type of line endings:
file test.txt
Output:
test.txt: ASCII text, with CRLF line terminators
Execute the dos2unix
command to convert line endings from DOS/Windows to Unix/Linux:
dos2unix test.txt
Use file
command to check the type of line endings. You will get the following output:
test.txt: ASCII text
Opposite command can be used as well. Convert line endings from Unix/Linux to DOS/Windows using unix2dos
command:
unix2dos test.txt
Uninstall Dos2Unix
If Dos2Unix is no longer necessary, you can remove it using command:
sudo apt purge --autoremove -y dos2unix
Leave a Comment
Cancel reply