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

目录
相关文章
|
7天前
|
Linux
Linux系统之whereis命令的基本使用
Linux系统之whereis命令的基本使用
50 23
Linux系统之whereis命令的基本使用
|
21天前
|
网络协议 Unix Linux
深入解析:Linux网络配置工具ifconfig与ip命令的全面对比
虽然 `ifconfig`作为一个经典的网络配置工具,简单易用,但其功能已经不能满足现代网络配置的需求。相比之下,`ip`命令不仅功能全面,而且提供了一致且简洁的语法,适用于各种网络配置场景。因此,在实际使用中,推荐逐步过渡到 `ip`命令,以更好地适应现代网络管理需求。
34 11
|
2月前
|
Linux Shell
Linux 10 个“who”命令示例
Linux 10 个“who”命令示例
100 14
Linux 10 个“who”命令示例
|
2月前
|
Ubuntu Linux
Linux 各发行版安装 ping 命令指南
如何在不同 Linux 发行版(Ubuntu/Debian、CentOS/RHEL/Fedora、Arch Linux、openSUSE、Alpine Linux)上安装 `ping` 命令,详细列出各发行版的安装步骤和验证方法,帮助系统管理员和网络工程师快速排查网络问题。
203 20
|
2月前
|
Linux
linux查看目录下的文件夹命令,find查找某个目录,但是不包括这个目录本身?
通过本文的介绍,您应该对如何在 Linux 系统中查看目录下的文件夹以及使用 `find` 命令查找特定目录内容并排除该目录本身有了清晰的理解。掌握这些命令和技巧,可以大大提高日常文件管理和查找操作的效率。 在实际应用中,灵活使用这些命令和参数,可以帮助您快速定位和管理文件和目录,满足各种复杂的文件系统操作需求。
143 8
|
2月前
|
网络协议 Linux 应用服务中间件
kali的常用命令汇总Linux
kali的常用命令汇总linux
128 7
|
3月前
|
Linux 数据库
Linux中第一次使用locate命令报错?????
在Linux CentOS7系统中,使用`locate`命令时出现“command not found”错误,原因是缺少`mlocate`包。解决方法是通过`yum install mlocate -y`或`apt-get install mlocate`安装该包,并执行`updatedb`更新数据库以解决后续的“can not stat”错误。
61 9
|
3月前
|
监控 网络协议 Linux
Linux netstat 命令详解
Linux netstat 命令详解
|
3月前
|
Windows
DOS 批处理 setlocal命令、endlocal命令详解
DOS 批处理 setlocal命令、endlocal命令详解
84 10
|
3月前
|
运维 监控 网络协议
运维工程师日常工作中最常用的20个Linux命令,涵盖文件操作、目录管理、权限设置、系统监控等方面
本文介绍了运维工程师日常工作中最常用的20个Linux命令,涵盖文件操作、目录管理、权限设置、系统监控等方面,旨在帮助读者提高工作效率。从基本的文件查看与编辑,到高级的网络配置与安全管理,这些命令是运维工作中的必备工具。
290 3