日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux命令学习总结:dos2unix - unix2dos

發布時間:2024/1/23 linux 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux命令学习总结:dos2unix - unix2dos 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

今天第一次接觸這個,做個記錄,最近覺得linux的東西知道的太少了,不行,得好好看點資料了。


命令簡介:

dos2unix是將Windows格式文件轉換為Unix、Linux格式的實用命令。Windows格式文件的換行符為\r\n ,而Unix&Linux文件的換行符為\n. dos2unix命令其實就是將文件中的\r\n 轉換為\n。

而unix2dos則是和dos2unix互為孿生的一個命令,它是將Linux&Unix格式文件轉換為Windows格式文件的命令。

?

命令語法

?

dos2unix [options] [-c convmode] [-o file ...] [-n infile outfile ...]

unix2dos [options] [-c convmode] [-o file ...] [-n infile outfile ...]

?

命令參數:

此命令參數是Red Hat Enterprise Linux Server release 5.7下dos2unix命令參數,不同版本Linux的dos2nnix命令參數有可能不同。

參數

長參數

描敘

-h

?

顯示命令dos2unix聯機幫助信息。

-k

?

保持文件時間戳不變

-q

?

靜默模式,不輸出轉換結果信息等

-V

?

顯示命令版本信息

-c

?

轉換模式

-o

?

在源文件轉換,默認參數

-n

?

保留原本的舊檔,將轉換后的內容輸出到新檔案.默認都會直接在原來的文件上修改,

?

使用示例:

1: 查看dos2unix命令的幫助信息

[root@DB-Server myscript]# man dos2unix ? [root@DB-Server myscript]# dos2unix -h dos2unix Copyright (c) 1994-1995 Benjamin Lin ???????? Copyright (c) 1998????? Bernd Johannes Wuebben (Version 3.0) ???????? Copyright (c) 1998????? Christian Wurll (Version 3.1) Usage: dos2unix [-hkqV] [-c convmode] [-o file ...] [-n infile outfile ...] -h --help??????? give this help -k --keepdate??? keep output file date -q --quiet?????? quiet mode, suppress all warnings ????????????????? always on in stdin->stdout mode -V --version???? display version number -c --convmode??? conversion mode convmode???????? ASCII, 7bit, ISO, Mac, default to ASCII -l --newline???? add additional newline in all but Mac convmode -o --oldfile???? write to old file file ...???????? files to convert in old file mode -n --newfile???? write to new file infile?????????? original file in new file mode outfile????????? output file in new file mode

?

2: dos2unix filename 將Windows格式文本轉換為Unix&Linux格式文件

1: [root@DB-Server myscript]# cat -v test.sh 2: . /home/oracle/.bash_profile^M 3: echo ' '^M 4: date^M 5: echo ' '^M 6: ^M 7: sqlplus test/test @/home/oracle/scripts/test.sql^M 8: ^M 9: echo ' '^M 10: date^M 11: echo ' '^M 12: [root@DB-Server myscript]# dos2unix test.sh 13: dos2unix: converting file test.sh to UNIX format ... 14: [root@DB-Server myscript]# cat -v test.sh 15: . /home/oracle/.bash_profile 16: echo ' ' 17: date 18: echo ' ' 19:? 20: sqlplus test/test @/home/oracle/scripts/test.sql 21:? 22: echo ' ' 23: date 24: echo ' '

?

3: dos2unix 可以一次轉換多個文件

1: dos2unix filename1 filename2 filename3

?

4: 默認情況下會在源文件上進行轉換,如果需要保留源文件,那么可以使用參數-n dos2unix -n oldfilename newfilename

1: [root@DB-Server myscript]# dos2unix -n dosfile linuxfile 2: dos2unix: converting file dosfile to file linuxfile in UNIX format ... 3: [root@DB-Server myscript]# cat -v dosfile 4: it is a windows dos file^M 5: you should convert to unix&linux format^M 6: [root@DB-Server myscript]# cat -v linuxfile 7: it is a windows dos file 8: you should convert to unix&linux format 9: [root@DB-Server myscript]#

?

5:保持文件時間戳不變

1: [root@DB-Server myscript]# ls -lrt dosfile 2: -rw-r--r-- 1 root root 67 Dec 26 11:46 dosfile 3: [root@DB-Server myscript]# dos2unix dosfile 4: dos2unix: converting file dosfile to UNIX format ... 5: [root@DB-Server myscript]# ls -lrt dosfile 6: -rw-r--r-- 1 root root 65 Dec 26 11:58 dosfile 7: [root@DB-Server myscript]# dos2unix -k dosfile 8: dos2unix: converting file dosfile to UNIX format ... 9: [root@DB-Server myscript]# ls -lrt dosfile 10: -rw-r--r-- 1 root root 65 Dec 26 11:58 dosfile

6:靜默模式格式化文件

1: [root@DB-Server myscript]# unix2dos -q dosfile 2:? 3: [root@DB-Server myscript]#

dos2unix的下載地址為http://sourceforge.net/projects/dos2unix/ ,可以從上面下載最新版本的dos2unix、unix2dos等命令工具以及相關文檔,dos2unix的源碼如下所示

1: /* 2: 3: *? Name: dos2unix 4: 5: *? Documentation: 6: 7: *??? Remove cr ('\x0d') characters from a file. 8: 9: * 10: 11: *? The dos2unix package is distributed under FreeBSD style license. 12: 13: *? See also http://www.freebsd.org/copyright/freebsd-license.html 14: 15: *? -------- 16: 17: * 18: 19: *? Copyright (C) 2009-2015 Erwin Waterlander 20: 21: *? Copyright (C) 1998 Christian Wurll 22: 23: *? Copyright (C) 1998 Bernd Johannes Wuebben 24: 25: *? Copyright (C) 1994-1995 Benjamin Lin. 26: 27: *? All rights reserved. 28: 29: * 30: 31: *? Redistribution and use in source and binary forms, with or without 32: 33: *? modification, are permitted provided that the following conditions 34: 35: *? are met: 36: 37: *? 1. Redistributions of source code must retain the above copyright 38: 39: *???? notice, this list of conditions and the following disclaimer. 40: 41: *? 2. Redistributions in binary form must reproduce the above copyright 42: 43: *???? notice in the documentation and/or other materials provided with 44: 45: *???? the distribution. 46: 47: * 48: 49: *? THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY 50: 51: *? EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 52: 53: *? IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 54: 55: *? PURPOSE ARE DISCLAIMED.? IN NO EVENT SHALL THE AUTHOR BE LIABLE 56: 57: *? FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 58: 59: *? CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 60: 61: *? OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 62: 63: *? BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 64: 65: *? WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 66: 67: *? OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 68: 69: *? IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 70: 71: * 72: 73: *? == 1.0 == 1989.10.04 == John Birchfield (jb@koko.csustan.edu) 74: 75: *? == 1.1 == 1994.12.20 == Benjamin Lin (blin@socs.uts.edu.au) 76: 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的Linux命令学习总结:dos2unix - unix2dos的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。