重定向的相關問題

2021-06-26 00:49:28 字數 1809 閱讀 6173

eg1、一般的重定向

[root@localhost tmp]# ls  

#列舉了下tmp資料夾下的檔案

dfg.txt  dfg.txtoo  keyring-9v0jw1  orbit-gdm  projecta  pulse-inzvcuhof66i  pulse-lwpkoorrhvkf  pulse-ogq88cpzndug  qwe.txt

[root@localhost tmp]# ls dfg.txt sd.txt#並不存在sd.txt這個檔案

ls: cannot access sd.txt: no such file or directory#輸出錯誤資訊

dfg.txt 

#這個是正確值

[root@localhost tmp]# ls dfg.txt sd.txt > file.txt

ls: cannot access sd.txt: no such file or directory  

#使用了重定向後輸出的錯誤資訊,發現只有在螢幕上輸出了錯誤資訊,沒有了正確的資訊了,因為這是重定向預設是正確值得重定向

[root@localhost tmp]# cat file.txt   

#瀏覽我們重定向的檔案,發現正確資訊重定向到了這裡

dfg.txt

eg2、正確資訊和錯誤資訊分別重定向

[root@localhost tmp]# ls

dfg.txt  dfg.txtoo  file.txt  keyring-9v0jw1  orbit-gdm  projecta  pulse-inzvcuhof66i  pulse-lwpkoorrhvkf  pulse-ogq88cpzndug  qwe.txt

[root@localhost tmp]# ls dfg.txt sd.txt 1>1.out 2>2.err 

#分別將資訊重定向到2個檔案中,螢幕上沒有了任何資訊

[root@localhost tmp]# cat 1.out 2.err  

#瀏覽2個檔案,發現正確資訊和錯誤資訊分別在這個2個檔案中了

dfg.txt 

ls: cannot access sd.txt: no such file or directory

eg3、

正確資訊和錯誤資訊重定向到乙個檔案中

[root@localhost tmp]# ls

1.out  dfg.txt    file.txt        orbit-gdm  pulse-inzvcuhof66i  pulse-ogq88cpzndug

2.err  dfg.txtoo  keyring-9v0jw1  projecta   pulse-lwpkoorrhvkf  qwe.txt

[root@localhost tmp]# ls dfg.txt sd.txt >3.out 2>&1 

#通過使用2>&1這個命令使得正確資訊和錯誤資訊都重定向到了乙個檔案中

[root@localhost tmp]# cat 3.out

ls: cannot access sd.txt: no such file or directory

dfg.txt

總結:注意這3個例子的不同之處:eg1只將正確的資訊重定向到了1個檔案中,eg2是將錯誤資訊個正確資訊分別重定向到了2個檔案中去,eg3是將正確資訊和錯誤資訊重定向到了1個檔案中

nginx rewrite 相關 重定向

rewrite指令的最後一項引數為flag標記,支援flag標記有 1.last 相當於apache裡面的 l 標記,表示rewrite。2.break本條規則匹配完成後,終止匹配,不再匹配後面的規則。3.redirect 返回302臨時重定向,瀏覽器位址會顯示跳轉後的url位址。4.permane...

重定向(Redirect)相關的幾個問題

此次掛接使用者中心,互動大都通過重定向 redirect 實現。期間也遇到了一些問題,總結如下。redirect原理及使用 1 重定向原理 重定向方式是在客戶端作的重定向處理。該方法通過修改 http 協議的 header 部分 對瀏覽器下達重定向指令的,讓瀏覽器對在 location 中指定的 u...

關於重定向的問題

1.標準輸入的控制 語法 命令 檔案將檔案做為命令的輸入。例如 mail s mail test wesongzhou hotmail.com file1 將檔案file1 當做信件的內容,主 題名稱為mail test,送給收信人。2.標準輸出的控制 語法 命令 檔案將命令的執行結果送至指定的檔案...