首頁>Club>
5
回覆列表
  • 1 # 使用者2154634393960013

    在Windows下換行時,有兩個字元:回車(/r)和換行(/n)。但在Linux下,只有一個換行(/n)

    可使用unix2dos和dos2unix命令進行格式的轉換:

    引數:

    -k 保持輸出檔案和輸入檔案的日期時間戳不變

    -o file 預設模式 . 將file轉換,並輸出到file

    -n infile outfile 新模式. 轉換infile, 並輸出到outfile

    1. unix2dos

    假設用vi新建一文字檔案,輸入123456

    [root@centos test]# ls -l a.txt

    -rw-r--r-- 1 root root 7 Jan 7 21:31 a.txt

    [root@centos test]# hexdump -c a.txt

    0000000 1 2 3 4 5 6 /n

    0000007

    [root@centos test]# unix2dos -n a.txt b.txt

    unix2dos: converting file a.txt to file b.txt in DOS format ...

    [root@centos test]# ls -l

    total 8

    -rw-r--r-- 1 root root 7 Jan 7 21:31 a.txt

    -rw------- 1 root root 8 Jan 7 21:34 b.txt

    [root@centos test]# hexdump -c a.txt

    0000000 1 2 3 4 5 6 /n

    0000007

    [root@centos test]# hexdump -c b.txt

    0000000 1 2 3 4 5 6 /r /n

    0000008

    b.txt是轉換後的DOS下的檔案

    2. dos2unix

    [root@centos test]# dos2unix -n b.txt c.txt

    dos2unix: converting file b.txt to file c.txt in UNIX format ...

    [root@centos test]# ls -l

    total 12

    -rw-r--r-- 1 root root 7 Jan 7 21:31 a.txt

    -rw------- 1 root root 8 Jan 7 21:34 b.txt

    -rw------- 1 root root 7 Jan 7 21:38 c.txt

    [root@centos test]# hexdump -c b.txt

    0000000 1 2 3 4 5 6 /r /n

    0000008

    [root@centos test]# hexdump -c c.txt

    0000000 1 2 3 4 5 6 /n

    0000007

    c.txt是轉換後unix下的文字檔案

  • 中秋節和大豐收的關聯?
  • 百度投資威馬汽車,騰訊也蠢蠢欲動,威馬汽車為何能吸引這麼多網際網路大佬?