Cyberithub

How to Install dos2unix command on Linux Using 7 Easy Steps

Advertisements

In this article, we will see how to install dos2unix command on Linux using 7 easy steps. dos2unix is a free and open source utility used to convert plain text files in dos format to unix format. It is installed as part of Dos2unix package. There is another utility called unix2dos which is also a part of Dos2unix package gets installed along with dos2unix utility. This utility is used to convert text files in unix format to dos format. The line breaks in Unix and DOS/Windows is treated differently.

Hence the file created in DOS/Windows based system needs to be converted to Unix format before it can be used properly in a Unix based systems. Similarly, a file created in Unix based systems needs to be converted to DOS/Windows format before it can be used properly on Windows based systems. Dos2unix package is available in default repo on almost all the famous linux distributions. So it can be easily installed through any of the available package manager. Here we will see the steps to install and use dos2unix command on Linux based systems.

 

How to Install dos2unix command on Linux Using 7 Easy Steps

How to Install dos2unix command on Linux Using 7 Easy Steps

Also Read: Solved "ssh: Could not resolve hostname xxxx" error in Linux

Step 1: Prerequisites

a) You should have a running Linux Server.

b) You should have sudo or root access to run privileged commands.

c) You should atleast have a package manager available in your System.

 

Step 2: Update Your Server

Before installing any package in your Systems, it is always recommended to install all the latest updates in your system and upgrade the required packages to the latest versions. You can choose to follow any of the below steps depending on the linux distribution you are currently using.

a) On Ubuntu/Debian System

If you are using an Ubuntu/Debian based system, then you need to run sudo apt update && sudo apt upgrade command as shown below.

cyberithub@ubuntu:~$ sudo apt update && sudo apt upgrade
Hit:2 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:3 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:4 https://dl.google.com/linux/chrome/deb stable InRelease [1,811 B]
Hit:5 https://deb.tableplus.com/debian/20 tableplus InRelease
Get:6 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Hit:1 https://downloads.apache.org/cassandra/debian 40x InRelease
Get:7 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:8 https://dl.google.com/linux/chrome/deb stable/main amd64 Packages [1,075 B]
Get:9 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [2,004 kB]
Get:10 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [2,384 kB]
Get:11 http://security.ubuntu.com/ubuntu focal-security/main i386 Packages [558 kB]
Get:12 http://in.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [788 kB]
Get:13 http://security.ubuntu.com/ubuntu focal-security/main Translation-en [327 kB]
Get:14 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [59.9 kB]
.................................................

b) On RHEL/CentOS System

If you are using a RHEL/CentOS based system, then you need to run sudo yum update && sudo yum upgrade or sudo dnf update && sudo dnf upgrade command as shown below.

[cyberithub@localhost ~]$ sudo yum update && sudo yum upgrade
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.nxtgen.com
* commercial-addons: repo.issabel.org
* epel: repo.extreme-ix.org
* extras: mirrors.nxtgen.com
* issabel-base: repo.issabel.org
* issabel-extras: repo.issabel.org
* issabel-updates: repo.issabel.org
* updates: mirrors.nxtgen.com
Resolving Dependencies
--> Running transaction check
---> Package bind-export-libs.x86_64 32:9.11.4-26.P2.el7_9.10 will be updated
---> Package bind-export-libs.x86_64 32:9.11.4-26.P2.el7_9.13 will be an update
---> Package bind-libs-lite.x86_64 32:9.11.4-26.P2.el7_9.10 will be updated
---> Package bind-libs-lite.x86_64 32:9.11.4-26.P2.el7_9.13 will be an update
---> Package bind-license.noarch 32:9.11.4-26.P2.el7_9.10 will be updated
---> Package bind-license.noarch 32:9.11.4-26.P2.el7_9.13 will be an update
---> Package golang.x86_64 0:1.17.12-1.el7 will be updated
---> Package golang.x86_64 0:1.18.9-1.el7 will be an update
.............................................

 

Step 3: Install dos2unix

In the next step you need to install dos2unix package in your System using below mentioned steps.

a) On Ubuntu/Debian System

If you are using a Ubuntu/Debian based systems, then you can install dos2unix package by using sudo apt install dos2unix command as shown below. This will download and install the package from default ubuntu repo along with all its dependencies.

cyberithub@ubuntu:~$ sudo apt install dos2unix
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
dos2unix
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 374 kB of archives.
After this operation, 1,342 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu focal/universe amd64 dos2unix amd64 7.4.0-2 [374 kB]
Fetched 374 kB in 2s (211 kB/s)
Selecting previously unselected package dos2unix.
(Reading database ... 195402 files and directories currently installed.)
Preparing to unpack .../dos2unix_7.4.0-2_amd64.deb ...
Unpacking dos2unix (7.4.0-2) ...
Setting up dos2unix (7.4.0-2) ...
Processing triggers for man-db (2.9.1-1) ...

b) On RHEL/CentOS System

Similarly, if you are using RHEL/CentOS based systems, then you can install dos2unix package by using sudo yum install dos2unix or sudo dnf install dos2unix command as shown below.

[cyberithub@localhost ~]$ sudo yum install dos2unix
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.nxtgen.com
* commercial-addons: repo.issabel.org
* epel: repo.extreme-ix.org
* extras: mirrors.nxtgen.com
* issabel-base: repo.issabel.org
* issabel-extras: repo.issabel.org
* issabel-updates: repo.issabel.org
* updates: mirrors.nxtgen.com
Resolving Dependencies
--> Running transaction check
---> Package dos2unix.x86_64 0:6.0.3-7.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================
Installing:
dos2unix x86_64 6.0.3-7.el7 base 74 k

Transaction Summary
=============================================================================================================================================================
Install 1 Package

Total download size: 74 k
Installed size: 190 k
Is this ok [y/d/N]: y
Downloading packages:
dos2unix-6.0.3-7.el7.x86_64.rpm | 74 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : dos2unix-6.0.3-7.el7.x86_64 1/1
Verifying : dos2unix-6.0.3-7.el7.x86_64 1/1

Installed:
dos2unix.x86_64 0:6.0.3-7.el7

Complete!

 

Step 4: Verify Installation

After successfully installing the package, you can verify the installed files path by using below command.

a) On Debian/Ubuntu System

To verify the installed files path on Debian/Ubuntu based systems, you can use dpkg -L dos2unix command as shown below.

cyberithub@ubuntu:~$ dpkg -L dos2unix
/.
/usr
/usr/bin
/usr/bin/dos2unix
/usr/bin/unix2dos
/usr/share
/usr/share/doc
/usr/share/doc/dos2unix
/usr/share/doc/dos2unix/BUGS.txt
/usr/share/doc/dos2unix/NEWS.txt.gz
/usr/share/doc/dos2unix/README.txt.gz
/usr/share/doc/dos2unix/TODO.txt
/usr/share/doc/dos2unix/changelog.Debian.gz
/usr/share/doc/dos2unix/copyright
/usr/share/doc/dos2unix/de
/usr/share/doc/dos2unix/de/dos2unix.htm
/usr/share/doc/dos2unix/de/dos2unix.txt.gz
/usr/share/doc/dos2unix/dos2unix.htm
/usr/share/doc/dos2unix/dos2unix.txt.gz
...............................................

b) On RHEL/CentOS System

To verify the installed files path on RHEL/CentOS based systems, you can use rpm -ql dos2unix command as shown below.

[cyberithub@localhost ~]$ rpm -ql dos2unix
/usr/bin/dos2unix
/usr/bin/mac2unix
/usr/bin/unix2dos
/usr/bin/unix2mac
/usr/share/doc/dos2unix-6.0.3
/usr/share/doc/dos2unix-6.0.3/COPYING.txt
/usr/share/doc/dos2unix-6.0.3/ChangeLog.txt
/usr/share/doc/dos2unix-6.0.3/NEWS.txt
/usr/share/doc/dos2unix-6.0.3/README.txt
/usr/share/doc/dos2unix-6.0.3/TODO.txt
/usr/share/doc/dos2unix-6.0.3/dos2unix.htm
/usr/share/locale/de/LC_MESSAGES/dos2unix.mo
/usr/share/locale/eo/LC_MESSAGES/dos2unix.mo
/usr/share/locale/es/LC_MESSAGES/dos2unix.mo
/usr/share/locale/nl/LC_MESSAGES/dos2unix.mo
/usr/share/man/es/man1/dos2unix.1.gz
/usr/share/man/es/man1/mac2unix.1.gz
/usr/share/man/es/man1/unix2dos.1.gz
/usr/share/man/es/man1/unix2mac.1.gz
/usr/share/man/man1/dos2unix.1.gz
/usr/share/man/man1/mac2unix.1.gz
/usr/share/man/man1/unix2dos.1.gz
/usr/share/man/man1/unix2mac.1.gz
/usr/share/man/nl/man1/dos2unix.1.gz
/usr/share/man/nl/man1/mac2unix.1.gz
/usr/share/man/nl/man1/unix2dos.1.gz
/usr/share/man/nl/man1/unix2mac.1.gz
You have new mail in /var/spool/mail/root

 

Step 5: Check Version

You can also check the current installed version by using dos2unix --version command as shown below.

cyberithub@ubuntu:~$ dos2unix --version
dos2unix 7.4.0 (2017-10-10)
With Unicode UTF-16 support.
With native language support.
With support to preserve the user and group ownership of files.
LOCALEDIR: /usr/share/locale
http://waterlan.home.xs4all.nl/dos2unix.html

 

Step 6: Using dos2unix

Now that dos2unix utility is installed, you can use it to convert a DOS/Windows based text file, such as hello.txt file in our case to Unix format by using dos2unix hello.txt command as shown below.

cyberithub@ubuntu:~$ dos2unix hello.txt
dos2unix: converting file hello.txt to Unix format...

 

Step 7: Uninstall dos2unix

Once you are done using dos2unix command, you can choose to uninstall it from your system by using any of the below given methods depending on the linux distribution you are currently using.

a) On Ubuntu/Debian System

If you have installed dos2unix package on a Ubuntu/Debian based system, then you can uninstall it by using sudo apt remove dos2unix command as shown below.

cyberithub@ubuntu:~$ sudo apt remove dos2unix
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
dos2unix
0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded.
After this operation, 1,342 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 195502 files and directories currently installed.)
Removing dos2unix (7.4.0-2) ...
Processing triggers for man-db (2.9.1-1) ...

b) On RHEL/CentOS/Fedora System

If you have installed dos2unix package on a RHEL/CentOS based system, then you can uninstall it by using sudo yum remove dos2unix or sudo dnf remove dos2unix command as shown below.

[cyberithub@localhost ~]$ sudo yum remove dos2unix
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package dos2unix.x86_64 0:6.0.3-7.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================
Removing:
dos2unix x86_64 6.0.3-7.el7 @base 190 k

Transaction Summary
=============================================================================================================================================================
Remove 1 Package

Installed size: 190 k
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : dos2unix-6.0.3-7.el7.x86_64 1/1
Verifying : dos2unix-6.0.3-7.el7.x86_64 1/1

Removed:
dos2unix.x86_64 0:6.0.3-7.el7

Complete!

Leave a Comment