Linux learning Accumulation (a) Dos2unix of Linux commands

Source: Internet
Author: User

Problem Description:

The error occurred while running a script yesterday,

Resolution process:

Asked the elder to know that the script was edited under Windows, need file conversion to run, and told me to use the Dos2unix command to convert.

Through the network query get the following knowledge, accumulate.

1. Why the shell scripts edited under Windows cannot run under Linux:

Dos text file is based on \ r \ n As a break mark, expressed as 16 binary is 0D 0 A. The text file under Unix is marked with \ n as a break mark, which means that the 16 binary is 0 a. The DOS format text file under Linux, with the lower version of VI Open the end of the ^m will be displayed, and many commands are not very good processing of this format of the file, if it is a shell script. The UNIX-formatted text files are displayed together when opened with Notepad under Windows.

2. Dos2unix effect

The Dos2unix command is used to convert a DOS-formatted text file into UNIX format (Dos/mac to UNIX text, format Converter)

3, the Help information of the command

-H--help give this Help
-k--keepdate Keep output file date
-Q--quiet Quiet mode, suppress all warnings
Always on Stdin->stdout mode
-V--version display version number
-C--convmode Conversion mode
Convmode ASCII, 7bit, ISO, Mac, default to ASCII
-L--newline Add additional newline in all but Mac Convmode
-O--oldfile write to old file
FILE-to-convert in-old file mode
-N--newfile write to new file
InFile original file in new file mode
outfile output file in new file mode

4. Use

Command format: Dos2unix file

5. Common parameters

-N Save as new file format: Dos2unix-n oldfile newfile

-K keep file timestamp unchanged format: dos2unix-k files

6. Usage examples

DOS Format files:

[email protected] newtest]# cat test.sh
#!/bin/sh

Date >job.txt

[Email protected] newtest]# sh test.sh
: Command not found
: Command not found

After converting with Dos2unix

[Email protected] newtest]# Dos2unix test.sh
dos2unix:converting file test.sh to UNIX format ...
[Email protected] newtest]# sh test.sh
[[email protected] newtest]# ls
Job.txt job.txt? Test.sh Xuguanyu
[email protected] newtest]# cat Job.txt
Tue Sep 11:20:17 EDT 2015

Linux learning Accumulation (a) Dos2unix of Linux commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.