Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use the dos2unix command

Shulou Source: shulou.com Published: 2022-06-01 03:10:27 09月27日 Update

This article will explain in detail how to use the dos2unix command, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

The os2unix command is used to convert text files in DOS format to UNIX format (DOS/MAC to UNIX text file format converter). The text file under DOS is marked with\ r\ nas a line breaker, which is 0D 0A in hexadecimal. The text file under Unix uses\ nas the line break flag, which is 0A in hexadecimal. Text files in DOS format are under Linux, and ^ M appears at the end of the line when opened with an earlier version of vi, and many commands do not handle this format very well, if it is a shell script. On the other hand, text files in Unix format will be displayed together when opened with Notepad under Windows. Therefore, there is a need to convert the two format files to each other, and the corresponding unix2dos command is to convert the UNIX format text file to DOS format.

1. Install dos2unix

Command: yum install-y dos2unix

Check to see if it is installed before installation:

[root@hadoop002 ~] # rpm-qa | grep-I dos2unix

[root@hadoop002 ~] #

If the instructions are not printed, they are not installed. Execute the command: yum install-y dos2unix to install.

Check again after the installation is complete:

[root@hadoop002 ~] # rpm-qa | grep-I dos2unix

Dos2unix-3.1-37.el6.x86_64

[root@hadoop002 ~] #

2. Dos2unix syntax:

Dos2unix [- hkqV] [- c convmode] [- o file...] [- n infile outfile...]

Parameter description:

-k: keep the date of the output file unchanged

-Q: quiet mode, no warning message.

-V: view version

-c: conversion patterns. Patterns are: ASCII, 7bit, ISO, Mac. Default is: ASCII.

-o: write to the source file

-n: write to a new file

3. Example

3.1 convert one file at a time

Dos2unix-k file

3.2 convert multiple files at a time

Dos2unix-k file1 file2 file3 or dos2unix-k-o file1 file2 file3

3.3 Save the results of the conversion in the new file, while the source file remains unchanged

Dos2unix-k-n oldfile newfile

About how to use the dos2unix command to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: File format command text mode content hexadecimal that is article more logo source file version knowledge article check good quiet time line message Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Tech Info Huawei OPPO Reno Apple