dos2unix 和 unix2dos

 [root@www ~]# dos2unix [-kn] file [newfile]

[root@www ~]# unix2dos [-kn] file [newfile]
选项与参数:
-k  :保留该档案原本的 mtime 时间格式 (不更新档案上次内容经过修订的时间)
-n  :保留原本的旧档,将转换后的内容输出到新档案,如: dos2unix -n old new
 
范例一:将刚刚上述练习的 /tmp/vitest/man.config 修改成为 dos 断行
[root@www ~]# cd /tmp/vitest
[root@www vitest]# cp -a /etc/man.config .
[root@www vitest]# ll man.config
-rw-r--r-- 1 root root 4617 Jan  6  2007 man.config
[root@www vitest]# unix2dos -k man.config
unix2dos: converting file man.config to DOS format ...
# 屏幕会显示上述的讯息,说明断行转为 DOS 格式了!
[root@www vitest]# ll man.config
-rw-r--r-- 1 root root 4758 Jan  6  2007 man.config
# 断行字符多了 ^M ,所以容量增加了!
 
范例二:将上述的 man.config 转成 man.config.linux 的 Linux 断行字符
[root@www vitest]# dos2unix -k -n man.config man.config.linux
dos2unix: converting file man.config to file man.config.linux in UNIX format ...
[root@www vitest]# ll man.config*
-rw-r--r-- 1 root root 4758 Jan  6  2007 man.config
-rw------- 1 root root 4617 Jan  6  2007 man.config.linux
因为断行字符以及 DOS 与 Linux 操作系统底下一些字符的定义不同,因此, 不建议你在 Windows 系统当中将档案编辑好之后,才上传到 Linux 系统,会容易发生错误问题。 而且,如果你在不同的系统之间复制一些纯文本档案时,千万记得要使用 unix2dos 或 dos2unix 来转换一下断行格式啊!

你可能感兴趣的:(dos2unix,unix2dos)