Linux-dos2unix-unix2dos-unix2mac

默认不带此命令,安装”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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值