Convert Text Files From DOS To Unix Format
From RZWiki
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
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
Related Articles
Information on Linux commands
Information on F5 BigIP commands
Information on Cisco commands
Information on Vyatta commands
Information on Extreme commands
Information on Zebra commands
Information on Secure Platform commands
Information on Blue Coat SGOS commands
Information on Nokia IPSO commands
(replacing the # with an @) |






