当前位置: 首页 > news >正文

Linux(Centos 7.6)命令详解:dos2unix

1.命令安装

dos2unix 命令默认情况下是没有安装的,如配置yum源,可通过yum安装命令如下:

yum install dos2unix

dos2unix 有一个对立的命令unix2dos,也需要yum安装,一般使用不到这里不做过多解释,具体参数可以与以下参考对比理解。

2.命令作用

将Windows格式文件件转换为Unix、Linux格式的文件(也可以转换成其他格式的)

3.命令语法

Usage: dos2unix [options] [file ...] [-n infile outfile ...]

4.参数详解

options:

  • -c, --convmode,转换方式,支持ascii, 7bit, iso, mac,默认为ascii
  • -f, --force,强制转换二进制文件
  • -k, --keepdate,保存输出文件日期
  • -l, --newline,添加额外的换行符
  • -n, --newfile,写入新文件
  • -o, --oldfile,写入旧文件(如果旧文件不存在会报错)
  • -q, --quiet,安静模式
  • -s, --safe,跳过二进制文件(默认)
  • -F, --follow-symlink,跟随符号链接文件转换链接实际文件(链接的实际文件会被转换)
  • -R, --replace-symlink,用转换后的文件替换符号链接(链接文件转换为实际文件且转换,原链接的实际文件不变)
  • -S, --skip-symlink,保持符号链接和目标不变(默认)

5.常用用例

注:以下测试转换文件是Windows上传至Centos的测试文件。

5.1.默认直接转换

[root@node2 Desktop]# file test1.txt 
test1.txt: ASCII text, with CRLF line terminators
[root@node2 Desktop]# 
[root@node2 Desktop]# dos2unix test1.txt 
dos2unix: converting file test1.txt to Unix format ...
[root@node2 Desktop]# 
[root@node2 Desktop]# file test1.txt 
test1.txt: ASCII text

5.2.静默直接转换

[root@node2 Desktop]# file test2.txt 
test2.txt: ASCII text, with CRLF line terminators
[root@node2 Desktop]# 
[root@node2 Desktop]# dos2unix -q test2.txt 
[root@node2 Desktop]# 
[root@node2 Desktop]# file test2.txt 
test2.txt: ASCII text

5.3.保持文件日期转换

注:文件日期不会改变

[root@node2 Desktop]# ll test3.txt 
-rwxr--r--. 1 root root 568 Jan 21 19:45 test3.txt
[root@node2 Desktop]# 
[root@node2 Desktop]# file test3.txt 
test3.txt: ASCII text, with CRLF line terminators
[root@node2 Desktop]# 
[root@node2 Desktop]# dos2unix -k test3.txt 
dos2unix: converting file test3.txt to Unix format ...
[root@node2 Desktop]# 
[root@node2 Desktop]# file test3.txt 
test3.txt: ASCII text
[root@node2 Desktop]# 
[root@node2 Desktop]# ll test3.txt 
-rwxr--r--. 1 root root 563 Jan 21 19:45 test3.txt

5.4.转换到新文件

[root@node2 Desktop]# file test4*
test4.txt: ASCII text, with CRLF line terminators
[root@node2 Desktop]# 
[root@node2 Desktop]# dos2unix -n test4.txt test4_1.txt
dos2unix: converting file test4.txt to file test4_1.txt in Unix format ...
[root@node2 Desktop]# 
[root@node2 Desktop]# file test4*
test4_1.txt: ASCII text
test4.txt:   ASCII text, with CRLF line terminators

5.5.级联转换链接文件

[root@node2 Desktop]# ll test5*
lrwxrwxrwx. 1 root root   9 Jan 21 19:51 test5_ln1.txt -> test5.txt
-rwxr--r--. 1 root root 568 Jan 21 19:45 test5.txt
[root@node2 Desktop]# file test5*
test5_ln1.txt: symbolic link to 'test5.txt'
test5.txt:     ASCII text, with CRLF line terminators
[root@node2 Desktop]# 
[root@node2 Desktop]# dos2unix -F test5_ln1.txt  ## 如不加-F参数,会跳过文件不转换
dos2unix: converting file test5_ln1.txt to Unix format ...
[root@node2 Desktop]# 
[root@node2 Desktop]# file test5*
test5_ln1.txt: symbolic link to 'test5.txt'
test5.txt:     ASCII text
http://www.lryc.cn/news/526602.html

相关文章:

  • Linux MySQL离线安装
  • 声明,这些内容和我无关
  • ISO:摄影中的光线敏感度密码
  • 长短期记忆网络LSTM
  • 2. 握手问题python解法——2024年省赛蓝桥杯真题
  • poi在word中打开本地文件
  • 国产编辑器EverEdit - 输出窗口
  • 整数的个数(信息学奥赛一本通-1067)
  • ios swift画中画技术尝试
  • MyBatis 写法
  • Three城市引擎地图插件Geo-3d
  • 【贪心算法】洛谷P1106 - 删数问题
  • WPS计算机二级•幻灯片的页面布局
  • 从入门到精通:HttpClient深度剖析与实战指南
  • IoTDB 2025 春节值班与祝福
  • Java 大视界 -- Java 大数据中的隐私增强技术全景解析(64)
  • 【2024年华为OD机试】 (A卷,100分)- 整理扑克牌(JavaScriptJava PythonC/C++)
  • 周末总结(2024/01/25)
  • Apache Flink 概述学习笔记
  • 双足机器人开源项目
  • Linux 部署 Java 项目:Tomcat、Redis、MySQL 教程
  • Django 多环境配置实战指南
  • 【C++高并发服务器WebServer】-6:信号
  • HBase的原理
  • [b01lers2020]Life on Mars1
  • Go学习:常量
  • Python 爬虫——爬取Web页面图片
  • 微信小程序1.1 微信小程序介绍
  • 记录备战第十六届蓝桥杯的过程
  • AI 编程工具—Cursor进阶使用 Rules for AI