1.功能:DOS/MAC文件转化成UNIX文件格式,功能跟notepad编辑器下的编辑-文档格式转换-转换为UNIX格式一样
2.安装方式:yum install -y dos2unix
3.语法:
dos2unix [options] [-c convmode] [-o file ...] [-n infile outfile ...]
4.参数:
-h --help 帮助
-k --keepdate 时间戳保持不变
-q --quiet 静默模式,不输出告警和信息
Quiet mode. Suppress all warning and messages.
-c --convmode 设定转化模式,模式有:ASCII, 7bit, ISO
-o --oldfile file 默认模式,将转换后的文件直接写到原文件中
-n --newfile infile outfile 将infile中的内容写入到outfile中
5.例子
[mysql@mysql ~]$ ls -lh
total 12K
-rw-r--r--. 1 root root 31 Jun 29 15:43 echo_test.sh
-rw-r--r--. 1 root root 18 Jun 29 15:41 test.txt
-rw-r--r--. 1 mysql dba 68 Jun 23 22:47 week.txt
#中间把test.txt、week.txt删除#
[mysql@mysql ~]$ dos2unix -k echo_test.sh
dos2unix: converting file echo_test.sh to UNIX format ...
[mysql@mysql ~]$ ls -lh
total 4.0K
-rw-r--r--. 1 mysql dba 30 Jun 29 15:43 echo_test.sh#时间戳未变
[mysql@mysql ~]$ dos2unix echo_test.sh
dos2unix: converting file echo_test.sh to UNIX format ...
[mysql@mysql ~]$ ls -lh
total 4.0K
-rw-r--r--. 1 mysql dba 30 Jun 29 16:03 echo_test.sh#时间戳变化
[mysql@mysql ~]$ dos2unix -n echo_test.sh test.sh
dos2unix: converting file echo_test.sh to file test.sh in UNIX format ...
[mysql@mysql ~]$ ls -lh
total 8.0K
-rw-r--r--. 1 mysql dba 30 Jun 29 16:03 echo_test.sh
-rw-r--r--. 1 mysql dba 30 Jun 29 16:03 test.sh
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
文章标题:Linux常用命令--dos2unix-创新互联
文章起源:http://tyjierui.cn/article/cecsci.html