Log in Go to the main page Page Discussion History Go to the file list Go to the site toolbox Bookmark and Share

Convert Text Files From DOS To Unix Format

From RZWiki


Image:linux-logo-large.png

Contents

File Format Issues

Most Linux users face text file format issues at some point, normally when attempting to run a bash script and receiving the error: bad interpreter: No such file or directory.

The file in question probably uses (unseen) CR/LFs characters to indicate the end of each line (DOS file format,) whilst Linux and Unix systems only support and recognise the CR character (UNIX ASCII file format.) This issue occurs frequently when files have been transferred from Windows and older MAC systems.

Before performing a conversion, you should confirm file format is the actual issue by eliminating these other possible causes;

  • Ensure the first line of your script contains: #!/bin/bash
  • Ensure the /bin/bash binary file exists
  • Call the script as a bash parameter: bash script-filename

Conversion

If the issue still persists, use one of the following solutions:

  • Use the dos2unix command to covert the file to the correct 'UNIX' ASCII format: dos2unix script-filename
  • Use this perl command: perl -i -pe's/\r$//;' script-filename

Image:accessories-text-editor-v2-medium.png Linux Usage Notes

With most Linux or Unix commands;

  • Non root users may need to prefix commands with the sudo command, for example: sudo chmod 644 *
  • Brief help can be displayed using the -h or --help parameter, for example: chmod --help
  • A full command manual can be displayed using the man command followed by the command name, for example: man chmod
  • Sometimes 'info' pages are used instead of or to provide more information than man pages; for example: info chmod
  • Version information can normally be display using the -v, -V or --version parameter, for example: chmod --version. However, this paramater is also frequently used to display verbose output.

noinclude/noinclude

Image:icemon-medium.png Related Articles

Information on Linux commands Image:Tux-small.png

Information on F5 BigIP commands Image:F5-logo-small.png

Information on Cisco commands Image:Cisco-logo-small.png

Information on Vyatta commands Image:Vyatta-logo-small.png

Information on Extreme commands Image:Extreme-logo-small.png

Information on Zebra commands

Information on Secure Platform commands

Information on Blue Coat SGOS commands

Information on Nokia IPSO commands


Image:internet-group-chat-small.png We really do appreciate all feedback so please do send your comments, suggestions or corrections to sjiveson#routerzone.eu
(replacing the # with an @)


Site Toolbox:

Personal tools
This page was last modified on 28 May 2009, at 17:31. - Disclaimers - About RZWiki
Powered by MediaWiki