Linux終端多使用者通訊實用命令

來源:互聯網
上載者:User

標籤:style   blog   ar   color   os   使用   sp   strong   on   

 

一  命令1.1 write

     該命令將當前終端(源)輸入的字元拷貝至目標使用者的終端,從而發送訊息給系統中某個使用者。用法如下:

#write <user>

   <msg>

   [Ctrl+D]或[Ctrl+C]

     當執行write命令時,目標使用者將得到如下格式的標題:

Message from 源使用者名稱@源主機 on 源字元終端 at 時:分 ...

     隨後輸入的字元文本將被拷貝至指定使用者的終端。目標使用者若想回應,也必須執行write命令。

     輸入結束後,鍵入EOF(Ctrl+D)字元或中斷(Ctrl+C)指令。目標使用者將看到EOF訊息,表明本次對話結束。

     當目標使用者登入多個終端時,可使用"write <user> <tty>"命令顯式地指定目標終端名稱。或者,交由write命令自動選擇空閑時間最短的那個終端(該終端通常當前在用)。

     注意,與write命令類似的還有talk命令。該命令為一個可視化通訊程式,用法更為複雜。

1.2 wall

     該命令發送訊息給系統中所有登入使用者。用法如下:

# wall <msg> 或

# wall

   <msg>

   [Ctrl+D]

     其中,訊息可作為wall命令的參數直接發送,也可寫入wall命令的標準輸入(此時訊息長度限制為22行,且必須以EOF鍵結束)。

     訊息發送完畢時,目標使用者將得到如下格式的標題和訊息:

Broadcast message from 源使用者名稱 (源字元終端) (星期 月 日 時:分:秒 年):

<空行>

訊息內容

     該命令忽略時區變數,即標題中列印的時間基於系統本地時間。

1.3 mesg

     該命令控制其他非root使用者對當前終端的寫訪問權,如是否允許其他使用者發來訊息。用法如下:

     該命令發送訊息給系統中所有登入使用者。用法如下:

# mesg [y|n]

     其中,y允許寫入當前終端,n則禁止寫入。若不指定選項y|n,則mesg命令輸出該終端的當前訪問狀態。

 

二  樣本

     上節命令使用樣本如下(wall命令未列出其他使用者的終端顯示):

 1 [[email protected] ~]$ w 2  11:30:58 up 85 days,  3:45, 20 users,  load average: 0.12, 1.82, 2.77 3 USER     TTY      FROM              [email protected]   IDLE   JCPU   PCPU WHAT 4 wangxiao pts/1    10.46.44.16      Mon09    0.00s 23.57s  0.00s sshd: wangxiaoyuan_ [priv] 5 root     pts/12   10.46.51.170     Mon15   19:49m  0.00s  0.00s -bash 6 litianch pts/15   10.46.44.16      10:42    9:52   0.02s  0.02s -bash 7 litianch pts/22   10.46.44.29      Fri17   20:39m  0.09s  0.09s -bash 8 [[email protected] ~]$ write litianchi 9 write: litianchi is logged in more than once; writing to pts/1510 hello tianchi, type ‘write wangxiaoyuan_‘ and press ENTER11 then enter ‘welcome!‘ and press Ctrl+D to send the message to me.12 //Ctrl+C13 [[email protected] ~]$ 14 Message from [email protected] on pts/1 at 10:43 ...15 hello tianchi, type ‘write wangxiaoyuan_‘ and press ENTER16 then enter ‘welcome!‘ and press Ctrl+D to send the message to me.17 EOF18 //Enter19 [[email protected] ~]$ write wangxiaoyuan_20 welcome!21 //Ctrl+D22 23 [[email protected] ~]$ 24 Message from [email protected] on pts/15 at 10:44 ...25 welcome!26 EOF27 //Enter28 [[email protected] ~] wall hello everyone!29 30 Broadcast message from wangxiaoyuan_ (pts/21) (Fri Oct 31 16:54:56 2014):31 32 hello everyone!33 34 [[email protected] ~]$ wall35 world!36 //Ctrl+C37 Broadcast message from wangxiaoyuan_ (pts/1) (Tue Nov 25 11:38:12 2014):38 39 world!40 41 [[email protected] ~]$ wall "Who‘s compling, please terminate! Just a test, pls go on..."42 [[email protected] ~]$ 43 Broadcast message from wangxiaoyuan_ (pts/21) (Fri Oct 31 17:25:03 2014):44 45 Who‘s compling, please terminate! Just a test, pls go on...46 47 [[email protected] ~]$ mesg48 is y49 [[email protected] ~]$ mesg n50 [[email protected] ~]$ mesg  51 is n52 [[email protected] ~]$ write litianchi pts/1553 write: litianchi has messages disabled on pts/15

 

三  總結

     本文所述的write和wall命令可能用於下述情況:

     1) 需要獨佔編譯資源時,可發送訊息通知不要再執行編譯任務;

     2) 急需編譯資源,而其他使用者又在編譯版本時,可發送訊息通知暫停;

     3) 遇到某使用者執行死迴圈佔用大量CPU時,可發送訊息提醒退出。

     不建議用於Linux系統使用者間聊天通訊(包括talk命令),畢竟過於原始。

 

 

Linux終端多使用者通訊實用命令

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.