The Dos2unix command is used to convert a DOS-formatted text file into Unix (Dos/mac to UNIX text, format Converter).
Dos text file line break is \ r \ n, which means that 16 binary is 0D 0 A, and Unix text file newline character is \ n, expressed as 16 binary is 0 a. DOS format text files on Linux with a lower version of VI Open Line end will show ^m, and many commands can not handle the file in this format, resulting in the two format files to convert each other requirements, corresponding to the UNIX format text file into a DOS format is the Unix2dos command.
Use Cat-v to view nonprinting characters in a file
Grammar:
dos2unix [-hkqV] [-c convmode] [-o file ...] [-n infile outfile ...]
Options:
-K: Keep the date of the output file unchanged
-Q: Quiet mode without prompting for any warning messages
-V: View version
-C: Conversion mode, Mode: ASCII, 7bit, ISO, Mac, default is: ASCII
-O: Writing to the source file
-N: Writing to a new file
Instance
Convert single or multiple files
The simplest use is to Dos2unix directly to a file or multiple files
Dos2unix file1 file2 file3 ...
Batch conversion of files in directory
Linux itself provides both the Dos2unix and Unix2dos commands for converting Windows and Linux files,
However, Dos2unix and unix2dos themselves do not provide recursive options, which are bulk modifications, so they can be implemented using the Xargs command. The purpose of the Xargs command is to convert the argument list to small pieces to pass to other commands.
Suppose the file that needs to be converted is in the same directory as Public/components
Find public/components/-name "*" | Xargs Dos2unix
Advantages: Batch conversion, small workload. Bulk conversions with pipe and xargs, this method enables bulk operations of other commands (such as bulk deletion, etc.)
Linux Text Format conversion