默认不带此命令,安装”dos2unix-unix2dos”命令。
yum install dos2unix
语法
dos2unix [-kn] file [newfile]
unix2dos [-kn] file [newfile]
作用
Windows格式文件、Unix(Linux)、MAC文件的互相转换。
Windows与Unix的换行符不同。
Windows是以”^M$”(CR,LF)为换行符,Unix(Linux)是以”$”(LF)为换行符。MAC是以”^M”(CR)为换行符。
参数
- -k
保留该文件的原来mtime时间格式 - -n
保留原来的旧文件,将转换后的文件输出至新文件
使用实例
转换
[root@192 Ethan]# unix2dos hello.c
unix2dos: converting file hello.c to DOS format ...
[root@192 Ethan]# cat -A hello.c
#include<stdio.h>^M$
void main(){^M$
^Iprintf("Hello world!");^M$
}^M$
[root@192 Ethan]# dos2unix hello.c
dos2unix: converting file hello.c to Unix format ...
[root@192 Ethan]# cat -A hello.c
#include<stdio.h>$
void main(){$
^Iprintf("Hello world!");$
}$
[root@192 Ethan]# unix2mac hello.c
unix2mac: converting file hello.c to Mac format ...
[root@192 Ethan]# cat -A hello.c
#include<stdio.h>^Mvoid main(){^M^Iprintf("Hello world!");^M}^M
下面使用“file”命令可以很清楚的看到换行符是什么:
[root@192 Ethan]# file hello.dos.c ;file hello.mac.c ;file hello.unix.c
hello.dos.c: C source, ASCII text, with CRLF line terminators
hello.mac.c: C source, ASCII text, with CR line terminators
hello.unix.c: C source, ASCII text
Tags: Linux