溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Linux dos2unix和unix2dos是的使用方法

發(fā)布時間:2020-08-09 04:14:36 來源:網(wǎng)絡(luò) 閱讀:13339 作者:DragonLinux 欄目:系統(tǒng)運維

    我們都知道Linux上的文件下載到windows系統(tǒng)上格式就亂了, 那我們怎么辦那 ?現(xiàn)在我教大家一個簡單的方法來解決Linux系統(tǒng)的文件下載到windows系統(tǒng)上會出現(xiàn)的文件格式亂的情況。


    dos2unix命令用來將DOS格式的文本文件轉(zhuǎn)換成UNIX格式的(DOS/MAC to UNIX text fileformat converter)。DOS下的文本文件是以\r\n作為斷行標志的,表示成十六進制就是0D0A.而Unix下的文本文件是以\n作為斷行標志的,表示成十六進制就是0A.

    DOS格式的文本文件在Linux底下,用較低版本的vi打開時行尾會顯示^M,而且很多命令都無法很好的處理這種格式的文件,如果是個shell腳本。而Unix格式的文本文件在Windows下用Notepad打開時會拼在一起顯示。因此產(chǎn)生了兩種格式文件相互轉(zhuǎn)換的需求,對應(yīng)的將UNIX格式文本文件轉(zhuǎn)成成DOS格式的是unix2dos命令。


 unix2dos 和 dos2unix


名稱


unix2dos-UNIX 到 DOS 文本文件格式轉(zhuǎn)換器

新思科技

unix2dos [選項] [-c convmode] [-o 文件......][-n infile 文件的輸出......]

選項:

[-hkqV][— — 幫助][-keepdate][— — 安靜][— — 版本]

常用參數(shù):

-k :保留文件運來的格式。

-n :保留原本的舊文件,將轉(zhuǎn)換后的內(nèi)容輸出到新文件。


unix2dos 例子:

從 stdin 中獲得輸入和輸出寫到標準輸出。

unix2dos

轉(zhuǎn)換和替換 a.txt。轉(zhuǎn)換和替換 b.txt。

[root@localhost ~]# unix2dos a.txt b.txt

[root@localhost ~]# unix2dos -o a.txt b.txt

轉(zhuǎn)換和替換 a.txt 中 ASCII 轉(zhuǎn)換模式。轉(zhuǎn)換和

替換 b.txt 的 ISO 轉(zhuǎn)換模式。

[root@localhost ~]# unix2dos a.txt-c iso b.txt

[root@localhost ~]# unix2dos -c ascii a.txt -c iso b.txt

轉(zhuǎn)換和替換 a.txt 同時保持原始日期戳。

[root@localhost ~]# unix2dos -k a.txt

[root@localhost ~]# unix2dos -k -o a.txt

轉(zhuǎn)換 a.txt 和寫入 e.txt。

[root@localhost ~]# unix2dos -n a.txt e.txt

轉(zhuǎn)換 a.txt 和寫入相同,e.txt,e.txt 保持日期戳

a.txt。

[root@localhost ~]# unix2dos -k -n a.txt e.txt

轉(zhuǎn)換和替換 a.txt。轉(zhuǎn)換 b.txt 和寫入 e.txt。

[root@localhost ~]# unix2dos a.txt -n b.txt e.txt

[root@localhost ~]# unix2dos -o a.txt -n  b.txt e.txt

轉(zhuǎn)換 c.txt 并寫入 e.txt。轉(zhuǎn)換和替換 a.txt。轉(zhuǎn)換

和替換 b.txt。轉(zhuǎn)換 d.txt 并寫入 f.txt。

[root@localhost ~]# unix2dos -n c.txt e.txt -o a.txt b.txt -n d.txt f.txt


dos2unix 例子:

從 stdin 中獲得輸入和輸出寫到標準輸出。

dos2unix

轉(zhuǎn)換和替換 a.txt。轉(zhuǎn)換和替換 b.txt。

[root@localhost ~]# dos2unix a.txt b.txt

[root@localhost ~]# dos2unix -o a.txt b.txt

轉(zhuǎn)換和替換 a.txt 中 ASCII 轉(zhuǎn)換模式。

[root@localhost ~]# dos2unix a.txt -c iso b.txt

轉(zhuǎn)換和替換 b.txt 的 ISO 轉(zhuǎn)換模式。

[root@localhost ~]# dos2unix -c ascii a.txt -c iso b.txt

Mac c.txt 轉(zhuǎn)換 Unix ascii 格式中。

[root@localhost ~]# dos2unix -c mac c.txt b.txt

轉(zhuǎn)換和替換 a.txt 同時保持原始日期。

[root@localhost ~]# dos2unix -k a.txt

[root@localhost ~]# dos2unix -k -o a.txt

轉(zhuǎn)換 a.txt 和寫入 e.txt。

[root@localhost ~]# dos2unix -n a.txt e.txt

轉(zhuǎn)換 a.txt 和寫入相同,e.txt,e.txt 保持日期戳

a.txt。

[root@localhost ~]# dos2unix -k -n a.txt e.txt

轉(zhuǎn)換和替換 a.txt。轉(zhuǎn)換 b.txt 和寫入 e.txt。

[root@localhost ~]# dos2unix a.txt -n b.txt e.txt

[root@localhost ~]# dos2unix -o a.txt -n b.txt e.txt

轉(zhuǎn)換 c.txt 并寫入 e.txt。轉(zhuǎn)換和替換 a.txt。轉(zhuǎn)換

和替換 b.txt。轉(zhuǎn)換 d.txt 并寫入 f.txt。

[root@localhost ~]# dos2unix -n c.txt e.txt -o a.txt b.txt -n d.txt f.txt


向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI