uTools-Manuals/docs/linux/dos2unix.html
2019-04-21 11:50:48 +08:00

32 lines
2.5 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<h1 id="dos2unix">dos2unix</h1>
<p>将DOS格式文本文件转换成Unix格式</p>
<h2 id="补充说明">补充说明</h2>
<p><strong>dos2unix命令</strong> 用来将DOS格式的文本文件转换成UNIX格式的DOS/MAC to UNIX text file format converter。DOS下的文本文件是以<code>\r\n</code>作为断行标志的表示成十六进制就是0D 0A。而Unix下的文本文件是以表示成十六进制就是0A。DOS格式的文本文件在Linux底下用较低版本的vi打开时行尾会显示<code>^M</code>而且很多命令都无法很好的处理这种格式的文件如果是个shell脚本。而Unix格式的文本文件在Windows下用Notepad打开时会拼在一起显示。因此产生了两种格式文件相互转换的需求对应的将UNIX格式文本文件转成成DOS格式的是unix2dos命令。</p>
<h3 id="语法">语法</h3>
<pre><code class="language-bash">dos2unix [-hkqV] [-c convmode] [-o file ...] [-n infile outfile ...]</code></pre>
<h3 id="选项">选项</h3>
<pre><code class="language-bash">-k保持输出文件的日期不变
-q安静模式不提示任何警告信息。
-V查看版本
-c转换模式模式有ASCII, 7bit, ISO, Mac, 默认是ASCII。
-o写入到源文件
-n写入到新文件</code></pre>
<h3 id="参数">参数</h3>
<p>参数:需要转换到文件。</p>
<h3 id="实例">实例</h3>
<p>最简单的用法就是dos2unix直接跟上文件名</p>
<pre><code class="language-bash">dos2unix file</code></pre>
<p>如果一次转换多个文件把这些文件名直接跟在dos2unix之后。也可以加上<code>-o</code>参数,也可以不加,效果一样)</p>
<pre><code class="language-bash">dos2unix file1 file2 file3
dos2unix -o file1 file2 file3</code></pre>
<p>上面在转换时,都会直接在原来的文件上修改,如果想把转换的结果保存在别的文件,而源文件不变,则可以使用<code>-n</code>参数。</p>
<pre><code class="language-bash">dos2unix oldfile newfile</code></pre>
<p>如果要保持文件时间戳不变,加上<code>-k</code>参数。所以上面几条命令都是可以加上<code>-k</code>参数来保持文件时间戳的。</p>
<pre><code class="language-bash">dos2unix -k file
dos2unix -k file1 file2 file3
dos2unix -k -o file1 file2 file3
dos2unix -k -n oldfile newfile</code></pre>
<p>转换当前目录下所有文件</p>
<pre><code class="language-bash">find -type f | xargs dos2unix</code></pre>
<!-- Linux命令行搜索引擎https://jaywcjlove.github.io/linux-command/ -->