Linux命令:dos2unix和unix2dos

dos2unix是将Windows格式文件转换为Unix、Linux格式的实用命令。Windows格式文件的换行符为\r\n ,而Unix&Linux文件的换行符为\n. dos2unix命令其实就是将文件中的\r\n 转换为\n。

而unix2dos则是和dos2unix互为孪生的一个命令,它是将Linux&Unix格式文件转换为Windows格式文件的命令。

 

实例:

1、dos2unix filename 将Windows格式文本转换为Unix&Linux格式文件

2、dos2unix 可以一次转换多个文件:dos2unix filename1 filename2 filename3

3、默认情况下会在源文件上进行转换,如果需要保留源文件,那么可以使用参数-n dos2unix -n oldfilename newfilename

5、保持文件时间戳不变:

1: [root@DB-Server myscript]# ls -lrt dosfile 
   2: -rw-r--r-- 1 root root 67 Dec 26 11:46 dosfile
   3: [root@DB-Server myscript]# dos2unix dosfile 
   4: dos2unix: converting file dosfile to UNIX format ...
   5: [root@DB-Server myscript]# ls -lrt dosfile 
   6: -rw-r--r-- 1 root root 65 Dec 26 11:58 dosfile
   7: [root@DB-Server myscript]# dos2unix -k dosfile 
   8: dos2unix: converting file dosfile to UNIX format ...
   9: [root@DB-Server myscript]# ls -lrt dosfile 
  10: -rw-r--r-- 1 root root 65 Dec 26 11:58 dosfile

 

6:静默模式格式化文件

   1: [root@DB-Server myscript]# unix2dos -q dosfile 
   2:  
   3: [root@DB-Server myscript]# 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值