
unix2dos
在 Unix/Linux 系统中,每一行以 换行符(LF,\n
\r\n
以下是一些常见的使用场景:
大多数 Linux 发行版默认未预装该工具,但可以通过包管理器轻松安装:
sudo apt-get update
sudo apt-get install dos2unix
<pre class="brush:php;toolbar:false;">sudo yum install dos2unix
通常
unix2dos
dos2unix
dos2unix
<pre class="brush:php;toolbar:false;">unix2dos [选项] 文件...
| 参数 | 说明 |
|---|---|
| `-b` 或 `--keep-bom` | 保留 UTF-8 字节顺序标记(BOM) |
| `-c` 或 `--convmode` | 指定转换模式(ascii, 7bit, iso, mac) |
| `-f` 或 `--force` | 强制转换二进制文件 |
| `-h` 或 `--help` | 输出帮助信息 |
| `-k` 或 `--keepdate` | 保持原文件时间戳不变 |
| `-L` 或 `--license` | 查看许可证信息 |
| `-l` 或 `--newline` | 仅添加换行符 |
| `-m` 或 `--add-bom` | 添加 UTF-8 字节顺序标记 |
| `-n` 或 `--newfile` | 写入新文件而不修改原始文件 |
| `-o` 或 `--oldfile` | 写入原始文件(默认行为) |
| `-q` 或 `--quiet` | 静默模式,不显示警告信息 |
| `-V` 或 `--version` | 显示版本号 |
将一个 Linux 格式的文本文件转为 Windows 格式:
<pre class="brush:php;toolbar:false;">unix2dos file.txt
这会直接修改
file.txt
如果希望保留源文件,可使用
-n
<pre class="brush:php;toolbar:false;">unix2dos -n unixfile.txt dosfile.txt
可以使用通配符来批量转换所有
.txt
<pre class="brush:php;toolbar:false;">unix2dos *.txt
结合
find
<pre class="brush:php;toolbar:false;">find . -name "*.sh" -exec unix2dos {} ;避免更改文件的时间戳信息:
<pre class="brush:php;toolbar:false;">unix2dos -k file.txt
如果你开发了一个 Linux Shell 脚本,但要在 Windows 的 Git Bash 或 WSL 中运行:
<pre class="brush:php;toolbar:false;">unix2dos script.sh
当你有一个需要在 Linux 和 Windows 平台都使用的配置文件:
<pre class="brush:php;toolbar:false;">unix2dos config.properties
将 Markdown 文档转为 Windows 兼容格式以便同事用记事本打开:
<pre class="brush:php;toolbar:false;">unix2dos README.md
-f
-m
dos2unix
可以使用
file
<pre class="brush:php;toolbar:false;">file filename.txt
或者用
cat
<pre class="brush:php;toolbar:false;">cat -A filename.txt
Unix 格式会在每行末尾显示
$
^M$
是的,因为每行多了一个
\r
可能是由于换行符格式不对,尝试使用
unix2dos
可以结合
file
unix2dos
unix2dos
在跨系统协作中,统一文本文件的格式规范有助于减少不必要的麻烦。
以上就是linux转换行尾符为DOS格式是什么-unix2dos 命令使用与实例的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号