Golfreeze.packetlove.com: Life style of Golfreeze Canon400D Family kammtan.com Jazz Freebsd Unix Linux System Admin guitar Music

All about unix linux freebsd and FAQ for Packetlove.com Web hosting , Mail hosting , VoIP + IP PBX server => command , shell script ,tool , crontab => Topic started by: golfreeze on พฤษภาคม 17, 2016, 02:50:24 PM

Title: ข้อแตกต่างและประโยชน์ของ screen vs tmux command in unix
Post by: golfreeze on พฤษภาคม 17, 2016, 02:50:24 PM
ปกติใน unix command ถ้าเรามีการ รัน command บางตัวที่ใช้เวลาในการโปรเซสนาน เช่น download kernel ไฟล์ใหญ่ๆ
หรือ install module application ใหญ่ๆอยู่ ซึ่ง ณ เวลานั้น เราจำเป็นต้องออกจากออฟฟิศ แล้วไป รีโมตเข้าไปเชคจากที่อื่นอยู่

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

(https://www.packetlove.com/th/wp-content/uploads/2016/05/Screen-Shot-2559-05-17-at-2.40.44-PM-670x335.png)

ยกตัวอย่าง สถานะการณ์ ครับ
ผมนั่งรีโมตไปยัง 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.dayid.org/comp/tm.html) และ http://www.packetlove.com (http://www.packetlove.com)
Title: Re: ข้อแตกต่างและประโยชน์ของ screen vs tmux command in unix
Post by: golfreeze on เมษายน 07, 2019, 01:56:59 PM
tmux เวลาจะกลับไป session ก่อนหน้า
Ctrl+b + l

Title: Re: ข้อแตกต่างและประโยชน์ของ screen vs tmux command in unix
Post by: golfreeze on มิถุนายน 05, 2019, 12:59:16 PM
==== 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 ====
Title: Re: ข้อแตกต่างและประโยชน์ของ screen vs tmux command in unix
Post by: golfreeze on กุมภาพันธ์ 26, 2021, 06:03:39 PM
ถ้าในกรณีเข้า ssh ผ่านมือถือ ขนาดหน้าจอของ tmux จะเป็น [41x30]
ถ้าจะกลับมาเข้าผ่าน mac terminal ให้มาเป็นขนาดปกติ ก็
เพื่อเป็นการเข้าไป tmux และทำการ detach ออกจาก sessionของ client อื่นๆด้วย

#tmux a -d

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

 8)
Title: Re: ข้อแตกต่างและประโยชน์ของ screen vs tmux command in unix
Post by: golfreeze on เมษายน 14, 2022, 11:15:06 AM
byobu command
ctrl+a+c = new window
ctrl+a+o = swap window
ctrl+a+% = split vertical view
Title: Re: ข้อแตกต่างและประโยชน์ของ screen vs tmux command in unix
Post by: golfreeze on ธันวาคม 04, 2022, 04:06:12 PM
tmux ดู output เก่าที่รันไปแล้ว
ctrl+b+[
แล้วเลื่อนลูกศร ขึ้นไปเรื่อยๆ  8)
Title: Re: ข้อแตกต่างและประโยชน์ของ screen vs tmux command in unix
Post by: golfreeze on มกราคม 26, 2023, 07:51:46 PM
ถ้าต้องการสร้าง tmux แล้วตั้งเป็นชื่อ session นี้
tmux new -s pklsession
tmux a -t pklsession

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