当前位置: 首页 > Linux

每天学一个Linux命令(35):dos2unix

时间:2023-04-06 04:22:35 Linux

昨天推荐:每天学一个Linux命令(34):wc命令介绍dos2unix命令用于将纯文本文件从DOS或Mac格式转换为Unix格式。DOS下的文本文件使用rn作为换行符,而Unix下的文本文件使用n作为换行符。默认系统没有安装此命令,用户需要自行安装:[root@centos7~]#dos2unixtest.txt-bash:dos2unix:commandnotfound#CentOS/RHEL安装[root@centos7~]#yuminstall-ydos2unix#Debian/Ubuntu安装[root@centos7~]#apt-getinstalldos2unix语法格式dos2unix[option][file]dos2unix[OPTION][FILE]optiondescription-k#输出文件的日期保留unchanged-q#quietmode-V#查看版本-c#转换模式,模式有:ASCII、7bit、ISO、Mac,默认为:ASCII。-o#写入源文件-n#写入新文件应用示例最简单的用法[root@centos7~]#dos2unixtest.txtdos2unix:convertingfiletest.txttoUnixformat...convertmultipleatatimeFile(注意:也可以加-o参数,也可以不加,效果一样)[root@centos7~]#dos2unixtest.txtmingongge.filedos2unix:convertingfiletest.txttoUnixformat...dos2unix:将文件mingongge.file转换为Unix格式...[root@centos7~]#dos2unix-otest.txtmingongge.filedos2unix:将文件test.txt转换为Unix格式...dos2unix:将文件mingongge.file转换为Unix格式。..转换时保持源文件不变(默认直接修改源文件),可以使用-n参数[root@centos7~]#lltest.txt-rw-r--r--1rootroot140Jan1611:32test.txt[root@centos7~]#dos2unix-ntest.txtdos_test.txtdos2unix:将文件test.txt转换为Unix格式的文件dos_test.txt...[root@centos7~]#lltest.txt-rw-r--r--1rootroot140Jan1611:32test.txt[root@centos7~]#lldos_test.txt-rw-r--r--1rootroot140Jan1611:34dos_test.txt如果想保持文件时间戳不变,加上-k参数[root@centos7~]#lltotal21892-rw-r--r--1rootroot140Jan1611:34dos_test.txt-rw-r--1rootroot0Jan1611:32mingongge.filedrwxr-xr-x3rootroot210Jan1610:19testdir-rw-r--r--1rootroot140Jan1611:32test.txt[root@centos7~]#dos2unixdos_test.txtdos2unix:正在将文件dos_test.txt转换为Unix格式...[root@centos7~]#lltotal21892-rw-r--r--1rootroot140Jan1611:36dos_test.txt-rw-r--1rootroot0Jan1611:32mingongge.filedrwxr-xr-x3rootroot210Jan1610:19testdir-rw-r--r--1rootroot140Jan1611:32test.txt#可以看出默认是修改了文件的时间消息[root@centos7~]#dos2unix-ktest.txtdos2unix:将文件test.txt转换为Unix格式...[root@centos7~]#dos2unix-kdos_test.txtmingongge.filedos2unix:将文件dos_test.txt转换为Unix格式...dos2unix:将文件mingongge.file转换为Unix格式...[root@centos7~]#lltotal21892-rw-r--r--1rootroot140Jan1611:36dos_test.txt-rw-r--r--1rootroot0Jan1611:32mingongge.fieldrwxr-xr-x3rootroot210Jan1610:19testdir-rw-r--r--1rootroot140Jan1611:32test.txt每天学一个Linux命令(32):sort每天学一个Linux命令(33):uniq