• dos2unix命令


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

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

    yum install -y dos2unix
    
    yum install -y unix2dos
    
    • 1
    • 2
    • 3

    命令用法:

    dos2unix [options] [-c convmode] [-o file ...] [-n infile outfile ...]
    
    unix2dos [options] [-c convmode] [-o file ...] [-n infile outfile ...]
    
    • 1
    • 2
    • 3

    示例:
    最简单的用法就是dos2unix直接跟上文件名:

    [root@cdn weihu]# dos2unix customer.yaml
    dos2unix: converting file customer.yaml to Unix format...
    
    • 1
    • 2

    如果一次转换多个文件,把这些文件名直接跟在dos2unix之后。(注:也可以加上-o参数,也可以不加,效果一样)

    [root@cdn weihu]# dos2unix  01-crd-all.gen.yaml  02-istio.yaml  customer.yaml
    dos2unix: converting file 01-crd-all.gen.yaml to Unix format...
    dos2unix: converting file 02-istio.yaml to Unix format...
    dos2unix: converting file customer.yaml to Unix format...
    [root@cdn weihu]#
    [root@cdn weihu]#
    [root@cdn weihu]# dos2unix -o  01-crd-all.gen.yaml  02-istio.yaml  customer.yaml
    dos2unix: converting file 01-crd-all.gen.yaml to Unix format...
    dos2unix: converting file 02-istio.yaml to Unix format...
    dos2unix: converting file customer.yaml to Unix format...
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    上面在转换时,都会直接在原来的文件上修改,如果想把转换的结果保存在别的文件,而源文件不变,则可以使用-n参数。

    [root@cdn weihu]# dos2unix -n customer.yaml  customer-test.yaml
    dos2unix: converting file customer.yaml to file customer-test.yaml in Unix format...
    [root@cdn weihu]#
    [root@cdn weihu]# ll
    total 412
    -rw-r--r--. 1 root root 275632 Nov 21 09:41 01-crd-all.gen.yaml
    -rw-r--r--. 1 root root 133119 Nov 21 09:41 02-istio.yaml
    -rw-r--r--. 1 root root    953 Nov 21 09:42 customer-test.yaml
    -rw-r--r--. 1 root root    953 Nov 21 09:41 customer.yaml
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
  • 相关阅读:
    D. Empty Graph #813 div2
    基于Java毕业设计音乐视频分享网站源码+系统+mysql+lw文档+部署软件
    docker 安装 superset
    【教材】*2022/11/29[指针] 指针数组作main函数的形参
    摘要,签名、加密方式、证书
    flowable工作流所有业务概念
    Contrastive Loss中参数τ的理解
    什么样的vue面试题答案才是面试官满意的
    Ubuntu下 Docker、Docker Compose 的安装教程
    Qt+sqlite3使用事务提升插入效率
  • 原文地址:https://blog.csdn.net/weixin_45432833/article/details/134524080