溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Linux基礎(chǔ)命令(5)

發(fā)布時(shí)間:2020-08-01 21:49:48 來(lái)源:網(wǎng)絡(luò) 閱讀:310 作者:mb5d2182ed97138 欄目:系統(tǒng)運(yùn)維
1、輸出重定向:
  標(biāo)準(zhǔn)輸出:是將信息輸出在終端上
  標(biāo)準(zhǔn)錯(cuò)誤輸出(2):在執(zhí)行命令的過(guò)程中所產(chǎn)生錯(cuò)誤信息也是
  輸出在終端
  標(biāo)準(zhǔn)輸入:是指從鍵盤輸入
2、標(biāo)準(zhǔn)輸出重定向(1)
  作用:將本來(lái)要顯示在標(biāo)準(zhǔn)輸出(終端)上的信息重定向到一個(gè)文件中
  如果文件不存在,則自動(dòng)創(chuàng)建文件。
  格式:
  >或者>>
  實(shí)現(xiàn)方式:
  1> 和 1>>
    >:將目標(biāo)文件中的內(nèi)容清空然后重新寫入
    >>:在原內(nèi)容后追加
    (如果文件不存在,則自動(dòng)創(chuàng)建文件)
    [root@7 home]# date +%F-%H:%M:%S > a.txt
    [root@7 home]# cat a.txt
    2019-08-14-16:59:04
    [root@7 home]# date +%F-%H:%M:%S >> a.txt
    [root@7 home]# date +%F-%H:%M:%S >> a.txt
    [root@7 home]# date +%F-%H:%M:%S >> a.txt
    [root@7 home]# cat a.txt
    2019-08-14-16:59:04
    2019-08-14-16:59:28
    2019-08-14-16:59:29
    2019-08-14-16:59:29
3、錯(cuò)誤輸出重定向
    格式:2> 或者2>>
    ####標(biāo)準(zhǔn)輸出  <<<僅將標(biāo)準(zhǔn)輸出定向到文件中   
    [root@7 home]# ls /home/ /tmp/ >>log.txt
    [root@7 home]# cat log.txt 
    /home/:
    a
    a.txt
    log.txt
    newbook
    /tmp/:
    1.txt
    2.txt
    Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)>
    book1
    book3
    systemd-private-022b00ef27664f60a4f5cc8a528584d3-chronyd.service-AqcaRu
    #####錯(cuò)誤輸出依然在終端
    [root@7 home]# ls /home/ /tmpa/ >>log.txt
    ls: cannot access /tmpa/: No such file or directory
    #####  2表示將錯(cuò)誤信息重定向,正確輸出依然在終端
    [root@7 home]# ls /home/ /tmpa/ 2>>log.txt
    /home/:
    a  a.txt  log.txt  newbook2
    例子:將正確信息保存到文件ok.txt文件中,將錯(cuò)誤信息保存到
error.txt文件中
    [root@7 home]# ls /home/ /tmpa/ >ok.txt 2>error.txt
    [root@7 home]# ls
    a  a.txt  error.txt  log.txt  newbook2  ok.txt
    [root@7 home]# cat ok.txt 
    /home/:
    a
    a.txt
    error.txt
    log.txt
    newbook2
    ok.txt
    [root@7 home]# cat error.txt 
    ls: cannot access /tmpa/: No such file or directory
4、tee命令
  作用:將信息同事輸出到終端和定向到文件中
  選項(xiàng):
  -a:將新的結(jié)果追加的文件末尾
(默認(rèn)是新的內(nèi)容覆蓋掉舊的內(nèi)容)
  [root@7 home]# echo "123" | tee 2.txt
  123
[root@7 home]# cat 2.txt 
  123
  [root@7 home]# echo "321" | tee 2.txt
  321
  [root@7 home]# cat 2.txt 
  例子:將/etc下的文件名記錄在文件log.txt中
  [root@7 home]# ls /etc >log.txt 
  例子:將a。txt中的前三行內(nèi)容顯示在桌面,同時(shí)保存文件info.txt中
[root@7 home]# head -n3 a.txt | tee info.txt
    2019-08-14-16:59:04
    2019-08-14-16:59:28
    2019-08-14-16:59:29
    [root@7 home]# cat info.txt
    2019-08-14-16:59:04
    2019-08-14-16:59:28
    2019-08-14-16:59:29
    例子:將文件a.txt內(nèi)容復(fù)制到b.txt
    [root@7 home]# cat a.txt >> b.txt
向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI