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

  • How to List Which Apache 2 Modules are Enabled on CentOS 6.x

    View Loaded Apache Modules Just one command: apachectl -M Or, if you want to view the list in alphabetical order: apachectl -M | sort Or, if you want to view...
  • Using Top [ $top ]

    What is Top? Top provides a live display of information on the CPU processes. Top gets updated periodically as it provides an output CPU level percentage, Memory size, Swap Info,...
  • Get CPU Information

    You can use the dmesg utility to display the contents of the system message buffer when FreeBSD comes up. For accuracy I recommend querying /var/run/dmesg.boot file. Usually a snapshot of...
  • SSH: Whitelist IPs for Your Server

    If you wish to whitelist certain IP’s for your server for any reason, you can easily go into your Webair Ezpanel for this. When whitelisting an IP, please provide the specific...