{"id":146,"date":"2019-07-15T10:18:14","date_gmt":"2019-07-15T06:18:14","guid":{"rendered":"http:\/\/kidds.co.za\/?p=146"},"modified":"2020-06-24T09:36:25","modified_gmt":"2020-06-24T05:36:25","slug":"tmux-quick-guide","status":"publish","type":"post","link":"https:\/\/kidds.co.za\/index.php\/2019\/07\/15\/tmux-quick-guide\/","title":{"rendered":"TMUX quick guide"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"shortcuts\">Whats is tmux<\/h2>\n\n\n\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Tmux\">https:\/\/en.wikipedia.org\/wiki\/Tmux<\/a><\/p>\n\n\n\n<p>tmux is basically an everlasting terminal that does not disappear when you logoff or get disconnected.<\/p>\n\n\n\n<p>Think of it as having an always open SSH session that will never go away unless you chose to close it.<\/p>\n\n\n\n<p>It is the easiest way and in my opinion best way to run commands or command line services that stop when you log off but you need them to keep running. Think something like McMyAdmin as an example.<\/p>\n\n\n\n<p>I have a simple txt file in my home directory that lists things i have running in various places which i update before logging off. It is very easy to forget that you started some server which requires the terminal to remain open in a tmux session, or you left a running process who&#8217;s output needs to be checked when completed.<\/p>\n\n\n\n<p>If i write a script that has an long expected run time, i will have this simply echo a line to the text file when it completes, so i login cat the txt file and new entry is there DATE &#8211; Script Name &#8211; Completed &#8211; tmux session name.<\/p>\n\n\n\n<p>This helps me avoid the, what the hell was i doing and what do i need to start \/ stop etc when coming back after a bit of time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"shortcuts\">Shortcuts<\/h2>\n\n\n\n<p>tmux commands are bound to a keyboard shortcut by default<\/p>\n\n\n\n<p>They\u2019re accessed by entering a key combination called the prefix and then typing a letter.<\/p>\n\n\n\n<p>For example, if you see&nbsp;<code>prefix + d<\/code>&nbsp;below, that means you would first hit (and release)&nbsp;<code>Control + b<\/code>&nbsp;and then type&nbsp;<code>d<\/code>.<\/p>\n\n\n\n<p>The prefix can also be changed<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"session-management\">Session Management<\/h2>\n\n\n\n<p>These are your goto commands. Aliassing some of these will make your life very easy. I have <strong>tll <\/strong>aliased to &#8220;<strong>tmux list-sessions<\/strong>&#8221; aliased in my bashrc file.<\/p>\n\n\n\n<p><code>tmux new -s session_name<\/code>creates a new tmux session named session_name<\/p>\n\n\n\n<p><code>tmux attach -t session_name<\/code>attaches to an existing tmux session named session_name. i.e. you log back on to the machine and reconnect to the session<\/p>\n\n\n\n<p><code>tmux switch -t session_name<\/code>switches to an existing session named session_name<\/p>\n\n\n\n<p><code>tmux list-sessions<\/code>lists existing tmux sessions. also uses alot until you remember the sessions you create by default. You could also simply create an alias in bash that reconnects you to your primary session.<\/p>\n\n\n\n<p><code>tmux detach (prefix + d)<\/code>detach the currently attached session<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"windows\">Windows<\/h2>\n\n\n\n<p>tmux has a tabbed interface, but it calls its tabs \u201cWindows\u201d. To stay organized, rename the windows if you use this. It will make your life easier;  <code>tmux new-window (prefix + c)<\/code>create a new window<\/p>\n\n\n\n<p><code>tmux select-window -t :0-9 (prefix + 0-9)<\/code>move to the window based on index<\/p>\n\n\n\n<p><code>tmux rename-window (prefix + ,)<\/code>rename the current window<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"panes\">Panes<\/h2>\n\n\n\n<p><code>tmux split-window (prefix + \")<\/code>splits the window into two vertical panes<\/p>\n\n\n\n<p><code>tmux split-window -h (prefix + %)<\/code>splits the window into two horizontal panes<\/p>\n\n\n\n<p><code>tmux swap-pane -[UDLR] (prefix + { or })<\/code>swaps pane with another in the specified direction<\/p>\n\n\n\n<p><code>tmux select-pane -[UDLR]<\/code>selects the next pane in the specified direction<\/p>\n\n\n\n<p><code>tmux select-pane -t :.+<\/code>selects the next pane in numerical order<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"helpful-tmux-commands\">Helpful tmux commands<\/h2>\n\n\n\n<p><code>tmux list-keys<\/code>lists out every bound key and the tmux command it runs<\/p>\n\n\n\n<p><code>tmux list-commands<\/code>lists out every tmux command and its arguments<\/p>\n\n\n\n<p><code>tmux info<\/code>lists out every session, window, pane, its pid, etc.<\/p>\n\n\n\n<p><code>tmux source-file ~\/.tmux.conf<\/code>reloads the current tmux configuration <\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Whats is tmux https:\/\/en.wikipedia.org\/wiki\/Tmux tmux is basically an everlasting terminal that does not disappear when you logoff or get disconnected. Think of it as having an always open SSH session that will never go away unless you chose to close it. It is the easiest way and in my opinion best way to run commands [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,2],"tags":[],"class_list":["post-146","post","type-post","status-publish","format-standard","hentry","category-general-commands","category-linux"],"_links":{"self":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/comments?post=146"}],"version-history":[{"count":1,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/146\/revisions"}],"predecessor-version":[{"id":147,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/146\/revisions\/147"}],"wp:attachment":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/media?parent=146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/categories?post=146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/tags?post=146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}