Linux命令(119)之dos2unix

简介: Linux命令(119)之dos2unix

linux命令之dos2unix

1.dos2unix介绍
linux命令dos2unix是用来将Windows格式文件转换为Linux格式文件的命令

2.dos2unix用法
dos2unix [参数] filename

参数 说明
-k 保留输出文件的时间
3.实例
3.1.转换Windows格式文件为Linux格式文件
有时在Windows环境下编写的Linux shell脚本,跨平台放置Linux环境后,由于结尾符的问题,存在其在Linux平台无法运行的问题。这时就需要转换Windows格式文件为Linux格式文件,可以让其在Linux环境运行。

Windows平台编写的Linux shell脚本放置Linux环境后,查看结尾符,可知Windows格式文件结尾符为^M$

命令:

cat -A test.sh

[root@rhel77 ztj.bak]# ls -l test.sh
-rwxr-xr-x 1 root root 26 Nov 10 20:03 test.sh
[root@rhel77 ztj.bak]#
[root@rhel77 ztj.bak]# cat -A test.sh

!/bin/bash^M$

echo "test"^M$
[root@rhel77 ztj.bak]#
转换Windows格式文件为Linux格式文件(保留原始时间)

dos2unix -k test.sh

[root@rhel77 ztj.bak]# dos2unix -k test.sh
dos2unix: converting file test.sh to Unix format ...
[root@rhel77 ztj.bak]# ls -l test.sh
-rwxr-xr-x 1 root root 24 Nov 10 20:03 test.sh
[root@rhel77 ztj.bak]#
转换为Linux格式文件后,查看结尾符,可知Linux格式文件结尾符为$

命令:

cat -A test.sh

[root@rhel77 ztj.bak]# cat -A test.sh

!/bin/bash$

echo "test"$
[root@rhel77 ztj.bak]#
运行

sh test.sh

[root@rhel77 ztj.bak]# sh test.sh
test
[root@rhel77 ztj.bak]#
3.2.查看其帮助信息
命令:

dos2unix --help

[root@rhel77 ztj.bak]# dos2unix --help
dos2unix 6.0.3 (2013-01-25)
Usage: dos2unix [options] [file ...] [-n infile outfile ...]
-ascii convert only line breaks (default)
-iso conversion between DOS and ISO-8859-1 character set
-1252 Use Windows code page 1252 (Western European)
-437 Use DOS code page 437 (US) (default)
-850 Use DOS code page 850 (Western European)
-860 Use DOS code page 860 (Portuguese)
-863 Use DOS code page 863 (French Canadian)
-865 Use DOS code page 865 (Nordic)
-7 Convert 8 bit characters to 7 bit space
-c, --convmode conversion mode
convmode ascii, 7bit, iso, mac, default to ascii
-f, --force force conversion of binary files
-h, --help give this help
-k, --keepdate keep output file date
-L, --license display software license
-l, --newline add additional newline
-m, --add-bom add UTF-8 Byte Order Mark
-n, --newfile write to new file
infile original file in new file mode
outfile output file in new file mode
-o, --oldfile write to old file
file ... files to convert in old file mode
-q, --quiet quiet mode, suppress all warnings
always on in stdio mode
-s, --safe skip binary files (default)
-F, --follow-symlink follow symbolic links and convert the targets
-R, --replace-symlink replace symbolic links with converted files
(original target files remain unchanged)
-S, --skip-symlink keep symbolic links and targets unchanged (default)
-V, --version display version number
[root@rhel77 ztj.bak]#

3.3.查看其版本信息
命令:

dos2unix -V

[root@rhel77 ztj.bak]# dos2unix -V
dos2unix 6.0.3 (2013-01-25)
With Unicode UTF-16 support.
With native language support.
LOCALEDIR: /usr/share/locale
[root@rhel77 ztj.bak]#
————————————————
版权声明:本文为CSDN博主「小黑要上天」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/z19861216/article/details/134340304

目录
相关文章
|
6天前
|
机器学习/深度学习 缓存 监控
linux查看CPU、内存、网络、磁盘IO命令
`Linux`系统中,使用`top`命令查看CPU状态,要查看CPU详细信息,可利用`cat /proc/cpuinfo`相关命令。`free`命令用于查看内存使用情况。网络相关命令包括`ifconfig`(查看网卡状态)、`ifdown/ifup`(禁用/启用网卡)、`netstat`(列出网络连接,如`-tuln`组合)以及`nslookup`、`ping`、`telnet`、`traceroute`等。磁盘IO方面,`iostat`(如`-k -p ALL`)显示磁盘IO统计,`iotop`(如`-o -d 1`)则用于查看磁盘IO瓶颈。
|
3天前
|
监控 Linux Windows
50个必知的Linux命令技巧,你都掌握了吗?(下)
50个必知的Linux命令技巧,你都掌握了吗?(下)
|
3天前
|
Linux Shell Windows
Linux 常用基本命令
Linux 常用基本命令
|
4天前
|
Ubuntu Linux Shell
linux免交互登陆远程主机并执行命令(密钥对和Expect)
linux免交互登陆远程主机并执行命令(密钥对和Expect)
|
4天前
|
Linux
【Linux】常用命令
【Linux】常用命令
24 0
|
4天前
|
安全 Ubuntu Linux
Linux 网络操作命令Telnet
Linux 网络操作命令Telnet
17 0
Linux 网络操作命令Telnet
|
5天前
|
Linux 数据安全/隐私保护
Linux常用命令实例带注释
Linux常用命令实例带注释
30 0
|
5天前
|
Linux 开发工具 数据安全/隐私保护
Linux(19)常用解压命令记录
Linux(19)常用解压命令记录
9 0
|
6天前
|
Linux Perl
Linux系统替换字符串常用命令
请注意,`sed`命令可以非常强大,可以根据不同的需求使用不同的选项和正则表达式来进行更复杂的字符串替换操作。
18 0
|
9天前
|
安全 Linux 开发工具
Linux中可引起文件时间戳改变的相关命令
【4月更文挑战第12天】Linux中可引起文件时间戳改变的相关命令
19 0