Author Topic: ข้อแตกต่างและประโยชน์ของ screen vs tmux command in unix  (Read 6083 times)

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
ปกติใน unix command ถ้าเรามีการ รัน command บางตัวที่ใช้เวลาในการโปรเซสนาน เช่น download kernel ไฟล์ใหญ่ๆ
หรือ install module application ใหญ่ๆอยู่ ซึ่ง ณ เวลานั้น เราจำเป็นต้องออกจากออฟฟิศ แล้วไป รีโมตเข้าไปเชคจากที่อื่นอยู่

ใน unix จะมี command อยู่ สองตัวที่ อำนวยความสะดวกให้ ครับนั่นคือ
1. screen
2. tmux



ยกตัวอย่าง สถานะการณ์ ครับ
ผมนั่งรีโมตไปยัง server A ผ่าน SSH จากเครื่อง notebook ที่ office
เพื่อที่จะอัฟเดท kernel ของ debian
#apt-get upgrade
มีขึ้นมาให้อัฟเกรด 65 packages ใช้เวลาประมาณ 25 นาทีได้ (เนตช้า 1MB share 50 คน )
แต่จังหวะนั้น แฟนผมโทรมาว่าลืมกุญแจ เข้าห้องไม่ได้ ต้องให้ผมกลับมาด่วน (555) เหตุการณ์สมมติ นะครับ อิอิ
ผมไม่อยากเสียเวลา เลยให้มัน download packages รอครับ ก็จัดโดย
#screen
#apt-get upgrade
ออกจาก terminal ของ ssh ในเครื่อง client
#ctrl a+d

มาถึงห้องแล้ว ไขกุญแจ เปิดห้องให้แฟนเรียบร้อย
ผมก็นั่ง จิบชา แล้วก็ remote ผ่าน SSH เข้าไปที่ server A
แล้วทำการ โยก session ที่ทำค้างไว้กลับมา
#screen -r -d

ก็จะสามารถใช้เวลาได้อย่างคุ้มค่ามากที่สุด ครับ ฮ่าๆๆ : )

ตัว screen และ tmux สามารถ split session ได้นะครับ
ถ้าใน screen ก็
ctrl a + S(ใหญ่)
แล้ว
ctrl a +tab
เพื่อเลื่อนลงมาอีกหน้าที่ split ออก
แล้วทำการ
ctrl a +a
เพื่อให้ command promt แสดงออกมา
เวลาจะออกจาก ตัว split ก็
ctrl a + d ครับ

ข้อแตกต่างระหว่าง tmux กับ screen ครับผม

Action   tmux   screen
start a new session   tmux OR
tmux new OR
tmux new-session   screen
re-attach a detached session   tmux attach OR
tmux attach-session   screen-r
re-attach an attached session (detaching it from elsewhere)   tmux attach -d OR
tmux attach-session -d   screen -dr
re-attach an attached session (keeping it attached elsewhere)   tmux attach OR
tmux attach-session   screen -x
detach from currently attached session   ^b d OR
^b :detach   ^a ^d OR
^a :detach
rename-window to newname   ^b , <newname> OR
^b :rename-window <newn>   ^a A <newname>
list windows   ^b w   ^a w
list windows in chooseable menu       ^a "
go to window #   ^b #   ^a #
go to last-active window   ^b l   ^a ^a
go to next window   ^b n   ^a n
go to previous window   ^b p   ^a p
see keybindings   ^b ?   ^a ?
list sessions   ^b s OR
tmux ls OR
tmux list-sessions   screen -ls
toggle visual bell       ^a ^g
create another window   ^b c   ^a c
exit current shell/window   ^d   ^d
split window/pane horizontally   ^b "   ^a S
split window/pane vertically   ^b %   ^a |
switch to other pane   ^b o   ^a <tab>
kill the current pane   ^b x OR (logout/^D)   
collapse the current pane/split (but leave processes running)       ^a X
close other panes except the current one   ^b !   
cycle location of panes   ^b ^o   
swap current pane with previous   ^b {   
swap current pane with next   ^b }   
show time   ^b t   
show numeric values of panes   ^b q   
toggle zoom-state of current pane (maximize/return current pane)   ^b z   
break the current pane out of its window (to form new window)   ^b !
Special thank : http://www.dayid.org/comp/tm.html และ http://www.packetlove.com

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
tmux เวลาจะกลับไป session ก่อนหน้า
Ctrl+b + l


golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
==== tmux trip by pkl ====
ctrl+b +w : show all pane and could select
ctrl+b +l : go to last session (switch session)
ctrl+b +% : split pane ขยายด้านข้าง ซ้าย ขวา
ctrl+b +” : split pane ขยายด้านบน ล่าง
ctrl+b +o : สลับระหว่าง pane
==== tmux trip by pkl ====
« Last Edit: มิถุนายน 05, 2019, 02:12:06 PM by golfreeze »

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: ข้อแตกต่างและประโยชน์ของ screen vs tmux command in unix
« Reply #3 on: กุมภาพันธ์ 26, 2021, 06:03:39 PM »
ถ้าในกรณีเข้า ssh ผ่านมือถือ ขนาดหน้าจอของ tmux จะเป็น [41x30]
ถ้าจะกลับมาเข้าผ่าน mac terminal ให้มาเป็นขนาดปกติ ก็
เพื่อเป็นการเข้าไป tmux และทำการ detach ออกจาก sessionของ client อื่นๆด้วย

#tmux a -d

คุณก็จะกลับมาที่ tmux ขนาดหน้าจอปกติ ประมาณ [181x53] ครับผม

 8)

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
byobu command
ctrl+a+c = new window
ctrl+a+o = swap window
ctrl+a+% = split vertical view

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
tmux ดู output เก่าที่รันไปแล้ว
ctrl+b+[
แล้วเลื่อนลูกศร ขึ้นไปเรื่อยๆ  8)

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
ถ้าต้องการสร้าง tmux แล้วตั้งเป็นชื่อ session นี้
tmux new -s pklsession
tmux a -t pklsession

ทำการ kill ทุก session ยกเว้นเหลือไว้แค่ pklsession
tmux kill-session -a -t pklsession