dos2unix Win-Linux format adjustment tool

In most Linux distributions, the dos2unix command can be used directly, so the following command can be used to check whether dos2unix has been installed in the system:

dos2unix --version

If the command can output version information normally, it means that dos2unix has been installed in the system. If it is not installed, you can install it with the following command:

On Debian/Ubuntu:

sudo apt-get install dos2unix

On CentOS/RHEL:

sudo yum install dos2unix

On Fedora:

sudo dnf install dos2unix

The basic syntax for using dos2unix is:

dos2unix [options] file(s)

Among them, the file(s) parameter is the file name to be converted, wildcards are supported, and the options parameter is an optional parameter. The following are some commonly used options:

  • -c, --convmode: Specifies the conversion mode, the default is ASCII mode.
  • -k, --keepdate: Keep file dates unchanged.
  • -n, --newfile: Generate a new file after conversion, the original file will not be modified.
  • -q, --quiet: Quiet mode, do not display the prompt information of the conversion process.

The following is a practical use case, assuming there is a file example.txt in Windows format that needs to be converted to Unix/Linux format:

  1. First, go to the directory where the file is located in the Linux terminal.

  2. Run the following command to see the file format:

    file example.txt
    

    The output is similar to:

    example.txt: ASCII text, with CRLF line terminators
    
  3. Run the following command to convert the file format:

    dos2unix example.txt
    

    If the command is executed successfully, a message similar to "converting file example.txt to Unix format..." will be output.

  4. Run the following command again to see the file format:

    file example.txt
    

    The output should be:

    example.txt: ASCII text
    

This case demonstrates how to use the dos2unix command to convert a text file in Windows format to Unix/Linux format for your reference.

Guess you like

Origin blog.csdn.net/m0_55877125/article/details/130601351