[20210929]帶有回車的檔案如何改名.txt

lfree發表於2021-09-29

[20210929]帶有回車的檔案如何改名.txt

--//http://www.itpub.net/thread-2143182-1-1.html,裡面涉及到redo log檔案該有換行符號,涉及到改名問題,
--//當然作者採用刪除再重建也是可以的,測試看看遇到這樣的情況如何改名.

$ mkdir Testz
$ cd Testz

$ touch "aaa^Jbbb"
--//^J 透過ctrl+v ctrl+J輸入. 這樣就建立帶有\n字元的檔案

$ ls -1 | xxd -c 16
0000000: 6161 610a 6262 620a                      aaa.bbb.

--//0x0a 代表\n.

--//改名很簡單.

 $ mv aaa?bbb aaa
`aaa\nbbb' -> `aaa'

$ ls -1 |xxd -c 16
0000000: 6161 610a                                aaa.

--//這樣就修改成沒有回車換行的檔案了.其它方法.

$ mv aaa aaa^Jbbb
/bin/mv: `aaa' and `aaa' are the same file
-bash: bbb: command not found

--//^_^,這樣寫變成了 mv aaa aaa bbb,加上引號ok.

$ mv aaa "aaa^Jbbb"
`aaa' -> `aaa\nbbb'

$ mv "aaa^Jbbb" aaa
`aaa\nbbb' -> `aaa'

--//在測試環境測試看看.
SYS@book> startup mount
ORACLE instance started.
Total System Global Area  643084288 bytes
Fixed Size                  2255872 bytes
Variable Size             205521920 bytes
Database Buffers          427819008 bytes
Redo Buffers                7487488 bytes
Database mounted.

SYS@book> @ logfile
GROUP# STATUS     TYPE       MEMBER                          IS_ GROUP# THREAD# SEQUENCE#       BYTES BLOCKSIZE MEMBERS ARC STATUS     FIRST_CHANGE# FIRST_TIME          NEXT_CHANGE# NEXT_TIME
------ ---------- ---------- ------------------------------- --- ------ ------- --------- ----------- --------- ------- --- ---------- ------------- ------------------- ------------ -------------------
     1            ONLINE     /mnt/ramdisk/book/redo01.log    NO       1       1      1346    52428800       512       1 YES INACTIVE     15026404702 2021-09-28 09:35:56  15026411573 2021-09-28 11:00:59
     2            ONLINE     /mnt/ramdisk/book/redo02.log    NO       2       1      1347    52428800       512       1 NO  CURRENT      15026411573 2021-09-28 11:00:59 2.814750E+14
     3            ONLINE     /mnt/ramdisk/book/redo03.log    NO       3       1      1345    52428800       512       1 YES INACTIVE     15026396123 2021-09-26 10:32:23  15026404702 2021-09-28 09:35:56
     4            STANDBY    /mnt/ramdisk/book/redostb01.log NO
     5            STANDBY    /mnt/ramdisk/book/redostb02.log NO
     6            STANDBY    /mnt/ramdisk/book/redostb03.log NO
     7            STANDBY    /mnt/ramdisk/book/redostb04.log NO
7 rows selected.

$ cd /mnt/ramdisk/book/
$ mv redo03.log "redo^J03.log"
`redo03.log' -> `redo\n03.log'

$ ll -b redo*
-rw-r----- 1 oracle oinstall 52429312 2021-09-29 09:01:13 redo01.log
-rw-r----- 1 oracle oinstall 52429312 2021-09-29 09:02:59 redo02.log
-rw-r----- 1 oracle oinstall 52429312 2021-09-29 09:01:13 redo\n03.log
-rw-r----- 1 oracle oinstall 52429312 2021-02-25 09:51:41 redostb01.log
-rw-r----- 1 oracle oinstall 52429312 2021-02-25 09:51:41 redostb02.log
-rw-r----- 1 oracle oinstall 52429312 2021-02-25 09:51:41 redostb03.log
-rw-r----- 1 oracle oinstall 52429312 2021-02-25 09:51:41 redostb04.log


SYS@book> alter database rename file '/mnt/ramdisk/book/redo03.log' to '/mnt/ramdisk/book/redo
  2  03.log';
Database altered.

SYS@book> @ logfile
GROUP# STATUS     TYPE       MEMBER                           IS_ GROUP# THREAD# SEQUENCE#       BYTES BLOCKSIZE MEMBERS ARC STATUS     FIRST_CHANGE# FIRST_TIME          NEXT_CHANGE# NEXT_TIME
------ ---------- ---------- -------------------------------- --- ------ ------- --------- ----------- --------- ------- --- ---------- ------------- ------------------- ------------ -------------------
     1            ONLINE     /mnt/ramdisk/book/redo01.log     NO       1       1      1346    52428800       512       1 YES INACTIVE     15026404702 2021-09-28 09:35:56  15026411573 2021-09-28 11:00:59
     2            ONLINE     /mnt/ramdisk/book/redo02.log     NO       2       1      1347    52428800       512       1 NO  CURRENT      15026411573 2021-09-28 11:00:59 2.814750E+14
     3            ONLINE     /mnt/ramdisk/book/redo           NO       3       1      1345    52428800       512       1 YES INACTIVE     15026396123 2021-09-26 10:32:23  15026404702 2021-09-28 09:35:56
                             03.log
     4            STANDBY    /mnt/ramdisk/book/redostb01.log  NO
     5            STANDBY    /mnt/ramdisk/book/redostb02.log  NO
     6            STANDBY    /mnt/ramdisk/book/redostb03.log  NO
     7            STANDBY    /mnt/ramdisk/book/redostb04.log  NO
7 rows selected.

--//能改成帶有\n的字元,再改回去應該很簡單了.
$ mv "redo^J03.log" redo03.log
`redo\n03.log' -> `redo03.log'

SYS@book> alter database rename file '/mnt/ramdisk/book/redo
  2  03.log' to '/mnt/ramdisk/book/redo03.log';
Database altered.

SYS@book> @ logfile
GROUP# STATUS     TYPE       MEMBER                          IS_ GROUP# THREAD# SEQUENCE#       BYTES BLOCKSIZE MEMBERS ARC STATUS     FIRST_CHANGE# FIRST_TIME          NEXT_CHANGE# NEXT_TIME
------ ---------- ---------- ------------------------------- --- ------ ------- --------- ----------- --------- ------- --- ---------- ------------- ------------------- ------------ -------------------
     1            ONLINE     /mnt/ramdisk/book/redo01.log    NO       1       1      1346    52428800       512       1 YES INACTIVE     15026404702 2021-09-28 09:35:56  15026411573 2021-09-28 11:00:59
     2            ONLINE     /mnt/ramdisk/book/redo02.log    NO       2       1      1347    52428800       512       1 NO  CURRENT      15026411573 2021-09-28 11:00:59 2.814750E+14
     3            ONLINE     /mnt/ramdisk/book/redo03.log    NO       3       1      1345    52428800       512       1 YES INACTIVE     15026396123 2021-09-26 10:32:23  15026404702 2021-09-28 09:35:56
     4            STANDBY    /mnt/ramdisk/book/redostb01.log NO
     5            STANDBY    /mnt/ramdisk/book/redostb02.log NO
     6            STANDBY    /mnt/ramdisk/book/redostb03.log NO
     7            STANDBY    /mnt/ramdisk/book/redostb04.log NO
7 rows selected.

$ ls -l redo0*
-rw-r----- 1 oracle oinstall 52429312 2021-09-29 09:01:13 redo01.log
-rw-r----- 1 oracle oinstall 52429312 2021-09-29 09:02:59 redo02.log
-rw-r----- 1 oracle oinstall 52429312 2021-09-29 09:01:13 redo03.log

SYS@book> alter database open ;
Database altered.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2794303/,如需轉載,請註明出處,否則將追究法律責任。

相關文章