有次在執行script,結果發現出現錯誤訊息,事後檢查發現原來問題出在斷行符號

當初是在xp下修改了一些東西再丟回到linux內,所以才會造成 command not find的問題

Windows環境下斷行符號是^M

Linux則是$

可用 cat –A 檔案      來觀看

dos2unix [-kn] file [newfile]

-k : 保留該文件原來的mtime時間格式(不更新文件上次內容經過修改的時間)

-n : 保留原來的舊文件,將轉換後的內容輸出到新文件,如:dos2unix -n old new

範例:

[root@linux ~]# mv hosts hosts.dos

[root@linux ~]# dos2unix -k -n hosts.dos hosts.linux

dos2unix: converting file hosts.dos to file hosts.linux in UNIX format …

[root@linux ~]# ll

-rw-r–r– 1 root root 288 Aug 1 13:30 hosts.dos

-rw——- 1 root root 279 Aug 1 13:30 hosts.linux

# 由於DOS格式中多了CR符號,所以文件比較大。

 

鳥哥那有詳細的說明http://linux.vbird.org/linux_basic/0310vi.php#tips_dos

arrow
arrow
    全站熱搜

    neo2124 發表在 痞客邦 留言(0) 人氣()