FreeBSD Linux Tips and Tricks

How to get rid of ^M characters.

When you edit a file in Windows and then open in UNIX, you must have seen ^M characters getting appended in the content. How to get rid of it ?

Most UNIX OS come with a utility called ‘dos2unix or dosunix (FreeBSD)’ . If it is not installed, please run following appropriate commands to install the utility and then convert appropriate file

  • Linux:

             yum install dos2unix

             dos2unix inputfile  >outputfile

  • FreeBSD:

            pkg install dosunix

            dosunix inputfile outputfile

Also, there are other ways to remove such characters as well:

  • Via Sed command:

           sed -e “s/^V^M//” inputfile > outputfile

          Note: Don’t paste the above command. Press Ctrl V and then Ctrl M in the above command instead.

  • Via vi editor:

    1. Open the file in vi.
    2. In the command mode, type :%s/^M//g.

          Note: Don’t type “^M”, but instead press “Ctrl V” and “Ctrl M” for it.

Related Articles

  • Disable SELinux

    Security-Enhanced Linux (SELinux) is a mandatory access control (MAC) security mechanism implemented in the Linux kernel. This mechanism adds an extra layer of access security to your files,directories,devices, ports and...
  • Reset MySQL Password

    Resetting a MySQL Root Password is one of the easiest things to do. However, finding documentation on how to do so can be challenging.   We as system administrators, have...
  • Users Logged Into Server

    This article explains on how to identify those who you do not know that are on your server. This can definitely eliminate the curiosity that people can have when taking...
  • Verify RPM package integrity

    In the case of Centos/RedHat OS, RPM tool can be used to verify the integrity of the installed package and check if any of the package has been compromised or not....