当前位置:网站首页 > 编程语言 > 正文

dos2unix命令使用方法(dos2linux)



linux 操作系统下 dos2unix 命令介绍和使用案例

dos2unix 命令介绍

dos2unix一个在 Linux 操作系统中使用的命令行工具,主要用于将 DOS 格式的文本文件转换为 Unix 格式。DOS 格式的文本文件使用回车符(CR)和换行符(LF)作为换行标志,即 ,而 Unix 格式则仅使用换行符 。因此,使用 dos2unix 可以解决在 Linux 系统中处理 Windows 格式文件时出现的换行符不匹配问题

命令安装部署

root@doris23:~# which dos2unix
root@doris23:~# dos2unix
Command 'dos2unix' not found, but can be installed with:
apt install dos2unix
root@doris23:~# apt install dos2nuix
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package dos2nuix
root@doris23:~# apt update
Hit:1 http://mirrors.aliyun.com/ubuntu focal InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu focal-security InRelease
Get:3 http://mirrors.aliyun.com/ubuntu focal-updates InRelease [128 kB]
Hit:4 http://mirrors.aliyun.com/ubuntu focal-backports InRelease                      
Ign:5 https://download.docker.com/linux/ubuntu jammy InRelease             
Ign:5 https://download.docker.com/linux/ubuntu jammy InRelease
Hit:5 https://download.docker.com/linux/ubuntu jammy InRelease
Fetched 128 kB in 4s (30.9 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
15 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@doris23:~# apt install dos2unix
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  dos2unix
0 upgraded, 1 newly installed, 0 to remove and 15 not upgraded.
Need to get 374 kB of archives.
After this operation, 1,342 kB of additional disk space will be used.
Get:1 http://mirrors.aliyun.com/ubuntu focal/universe amd64 dos2unix amd64 7.4.0-2 [374 kB]
Fetched 374 kB in 0s (1,079 kB/s)
Selecting previously unselected package dos2unix.
(Reading database ... 74417 files and directories currently installed.)
Preparing to unpack .https://blog.csdn.net/lisanmengmeng/article/dos2unix_7.4.0-2_amd64.deb ...
Unpacking dos2unix (7.4.0-2) ...
Setting up dos2unix (7.4.0-2) ...
Processing triggers for man-db (2.10.2-1) ...
Scanning processes...                                                                                                                                       
Scanning linux images...                                                                                                                                    

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

命令使用介绍

root@doris23:~# dos2unix --help
Usage: dos2unix [options] [file ...] [-n infile outfile ...]
 --allow-chown         allow file ownership change
 -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
 -b, --keep-bom        keep Byte Order Mark
 -c, --convmode        conversion mode
   convmode            ascii, 7bit, iso, mac, default to ascii
 -f, --force           force conversion of binary files
 -h, --help            display this help text
 -i, --info[=FLAGS]    display file information
   file ...            files to analyze
 -k, --keepdate        keep output file date
 -L, --license         display software license
 -l, --newline         add additional newline
 -m, --add-bom         add Byte Order Mark (default UTF-8)
 -n, --newfile         write to new file
   infile              original file in new-file mode
   outfile             output file in new-file mode
 --no-allow-chown      don't allow file ownership change (default)
 -o, --oldfile         write to old file (default)
   file ...            files to convert in old-file mode
 -q, --quiet           quiet mode, suppress all warnings
 -r, --remove-bom      remove Byte Order Mark (default)
 -s, --safe            skip binary files (default)
 -u,  --keep-utf16     keep UTF-16 encoding
 -ul, --assume-utf16le assume that the input format is UTF-16LE
 -ub, --assume-utf16be assume that the input format is UTF-16BE
 -v,  --verbose        verbose operation
 -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
 

dos2unix 的基本语法如下:

bash

其中, 为可选参数,, 等为要转换格式的文件名

  • :保持输出文件的日期不变。
  • :安静模式,不显示任何警告信息。
  • :查看版本信息。
  • :指定转换模式(如 ASCII、7bit、ISO 等),默认为 ASCII。
  • :写入到源文件。
  • :将转换结果写入新文件,而不修改原文件

案例使用

root@doris23:~# ls
AI服务代码相关.txt  snap
root@doris23:~# cat AI服务代码相关.txt 
204.150 /data/longsz/anaconda3  64G
204.155 /data/longsz/anaconda3  85G
204.154 /data/weisy  524G    

#τ¼þ±¸·
/data/backup_env
keep_gitlab-bk-.tgzroot@doris23:~# file AI服务代码相关.txt 
AI服务代码相关.txt: ISO-8859 text, with CRLF line terminators
root@doris23:~# dos2unix AI服务代码相关.txt 
dos2unix: converting file AI服务代码相关.txt to Unix format...
root@doris23:~# file AI服务代码相关.txt 
AI服务代码相关.txt: ISO-8859 text
root@doris23:~# cat AI服务代码相关.txt 
204.150 /data/longsz/anaconda3  64G
204.155 /data/longsz/anaconda3  85G
204.154 /data/weisy  524G    

#τ¼þ±¸·
/data/backup_env
keep_gitlab-bk-.tgzroot@doris23:~# 

到此这篇dos2unix命令使用方法(dos2linux)的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!

版权声明


相关文章:

  • 查看文件权限及所有者(查看文件的权限)2025-04-27 22:18:07
  • libxml2(libxml2源码)2025-04-27 22:18:07
  • 打不开et文件怎么办(et文件手机打不开怎么办)2025-04-27 22:18:07
  • 体育游戏的分类一般应选择(体育游戏的分类一般应选择什么方法)2025-04-27 22:18:07
  • vb服装是什么牌子(vbh是什么品牌)2025-04-27 22:18:07
  • 最终幻想7战斗系统无聊(最终幻想7战斗员)2025-04-27 22:18:07
  • 批量删除文件名相同字符(批量删除文件名中特定文字)2025-04-27 22:18:07
  • msp432单片机(msp430f149单片机)2025-04-27 22:18:07
  • keil破解版下载(keil最新破解器)2025-04-27 22:18:07
  • ip网址查询域名(ip地址查询域名)2025-04-27 22:18:07
  • 全屏图片