Stories
Slash Boxes
Comments

SoylentNews is people

SoylentNews is powered by your submissions, so send in your scoop. Only 18 submissions in the queue.
posted by Fnord666 on Wednesday September 25 2019, @03:43AM   Printer-friendly
from the multitasking dept.

Arthur T Knackerbracket has found the following story:

Tmux is a very powerful terminal multiplexer which is extremely useful especially when you are using the remote server via SSH.

If we want to do multiple tasks simultaneously on the remote server, usually we have to two ways to do it. We could SSH into the remote server and run everything in the background with an ‘&’ at the end of each terminal command. This is problematic if you want to monitor the process of each task. We could also open multiple windows, SSH into the remote server for each window, and run one task for each window. This is good for monitoring all the tasks, but the shortcoming is that you would have to type your SSH login information for each of the windows you opened. Sometimes it is also hard to find which window is doing which task if there are too many windows opened.

Tmux allows the user to create multiple sessions and each session could have multiple terminals. The user would be able to control multiple tasks in multiple windows via Tmux. No more multiple SSH logins anymore. However, Tmux is not very friendly to beginners because you would have to memorize a series of commands required for controlling Tmux. Although Tmux is much useful than a terminal emulator such as Gnome Terminator, many users would just like to use Tmux as a multi-window terminal emulator. However, Tmux does not memorize user settings such as pane layouts, so every time after reboot or restart the Tmux server, all of the user settings will be gone.

In this short tutorial, I am going through some of the basic concepts and commands for Tmux, and how to use a Tmux plugin, which is called Tmux Resurrect, to restore Tmux environment after reboot or Tmux server restart.


Original Submission

 
This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 5, Insightful) by NotSanguine on Wednesday September 25 2019, @04:28AM (5 children)

    by NotSanguine (285) <{NotSanguine} {at} {SoylentNews.Org}> on Wednesday September 25 2019, @04:28AM (#898388) Homepage Journal

    GNU screen [gnu.org] or Twin [github.com], mtm [github.com] or even Byobu [byobu.co]?

    Not trashing tmux here, just curious as to what Soylentils think of various different terminal multiplexers.

    --
    No, no, you're not thinking; you're just being logical. --Niels Bohr
    Starting Score:    1  point
    Moderation   +3  
       Insightful=2, Informative=1, Total=3
    Extra 'Insightful' Modifier   0  
    Karma-Bonus Modifier   +1  

    Total Score:   5  
  • (Score: 1, Interesting) by Anonymous Coward on Wednesday September 25 2019, @04:43AM

    by Anonymous Coward on Wednesday September 25 2019, @04:43AM (#898393)

    I've used screen whenever I needed to run something that wouldn't finish within a reasonable time-frame.
    otherwise I prefer multiple local terminals (tabs and/or multiple windows), with separate ssh sessions for each one: this way I don't have to use yet another mechanism for switching between the different bash prompts.

  • (Score: 3, Interesting) by The Mighty Buzzard on Wednesday September 25 2019, @04:54AM

    by The Mighty Buzzard (18) Subscriber Badge <themightybuzzard@proton.me> on Wednesday September 25 2019, @04:54AM (#898394) Homepage Journal

    Six of one, half a dozen of the other to me. I only bother with them when I'm skeptical on the reliability of my connection or I plan on leaving the terminal window open for a long time. A tabbed terminal window covers 99.995% of the use I might ever have for one and I only have to remember five key combinations at most.

    --
    My rights don't end where your fear begins.
  • (Score: 4, Informative) by Marand on Wednesday September 25 2019, @08:12AM

    by Marand (1081) on Wednesday September 25 2019, @08:12AM (#898415) Journal

    Never used Twin or mtm, can't say much about them. Though from what I just read, it sounds like Twin creates its own window and does its own terminal emulation, which IMO makes it a completely different sort of tool that should probably be compared to terminal emulators, not multiplexers. Similarly, Byobu is a slightly different category of thing: a set of enhancements on top of screen (or tmux, apparently), like spacemacs is to emacs rather than a standalone piece of software. Not mentioned in your comment, but I've also used dvtm [brain-dump.org].

    Tmux is basically a superset of Screen. It does the same things, does many of them better, and has extra things. That makes it easy to switch to if you're already familiar with Screen. The tmux default of using ^B for command prefix will throw you off, but can be fixed by adding "set-option -g prefix C-a" to your tmux config. Once that's done you just use it like Screen and slowly add in new features as you discover them, which is how I got going with tmux. The ^A muscle memory is too strong, and hitting it is too convenient compared to ^B; I just couldn't make the switch to tmux until I changed that.

    Dvtm, on the other hand, is a completely different beast. Where tmux and screen are basically manual tiling WMs, dvtm is the terminal equivalent to automatic tiling window managers like awesome. You create new panes and it automatically resizes existing ones based on the current pane layout choice (vertical, bottom, grid, fullscreen), no manual management used. Its status bar (if enabled) follows a different philosophy as well, displaying text you feed to it via a FIFO. That means it can display just about anything, but requires a bit more effort than building a status bar from a list of provided features, tmux-style. Another difference is it's a "does one thing well" type of program and thus doesn't provide detach/reattach functionality; for that you have to use a separate program like dtach.

    I use both dvtm and tmux, but of the two, tmux gets far more day to day use. I generally prefer manual tiling WMs, so the tmux/screen pane splitting style generally suits me more than the hands-off approach of dvtm. Plus being able to attach multiple clients to a single tmux session is really useful for interacting with a system seamlessly from multiple computers.

  • (Score: 3, Interesting) by Sourcery42 on Wednesday September 25 2019, @09:14PM (1 child)

    by Sourcery42 (6400) on Wednesday September 25 2019, @09:14PM (#898758)

    Screen works great. I've gotten to where I start up screen every time I login to something over ssh, if just for the multiple sessions in one terminal window capability. It is great for long running tasks if you're concerned about dodgy connections. Also handy to login from a computer with a real keyboard, start screen, start job, detach screen, login from phone, attach to screen to monitor progress remotely.

    From skimming TFA, it seems tmux might have some additional features, but nothing I really see myself getting any value out of versus screen. ctrl + a changing to ctrl + b would mess my head up for a while too.

    • (Score: 3, Interesting) by Marand on Thursday September 26 2019, @02:00AM

      by Marand (1081) on Thursday September 26 2019, @02:00AM (#898897) Journal

      It is great for long running tasks if you're concerned about dodgy connections

      Using Mosh [mosh.org] instead of ssh is a better choice for dodgy connections on a single machine. It negotiates the connection with ssh to start, but once set up, everything's over UDP and resilient against connectivity losses, including swapping to a completely different connection, such as switching to/from wifi on a device with a mobile radio.

      The strength of screen or tmux is maintaining a single session across multiple devices. And for that, tmux wins over screen, with a better handling of sessions and multiple attached clients. (A blogpost detailing some of the differences [wtanaka.com].) Tmux manages multiple sessions in a single instance, letting clients hop over from one session to another easily, move or clone windows across sessions, etc. It also provides a keybind that brings up a useful interactive tree-view of all running sessions, windows, and panes, including a live preview of the contents of each, which I've found extremely helpful with managing multiple long-running tmux sessions. Its improvements over screen make it much more useful across multiple systems and as a terminal "window manager".

      ctrl + a changing to ctrl + b would mess my head up for a while too.

      No need, you can just change the keybind and use it like you always have. I absolutely hate ^B as the prefix and immediately changed it back to ^A for ergonomic reasons. Put "set-option -g prefix C-a" into ~/.tmux.conf and keep the muscle memory like I did. If you ever need to send ^A, you can also add "bind-key C-a send-prefix" so that ^A ^A will pass a single ^A through to the shell.

      That said, I'm now seriously considering doing something mentioned in the comments of that screen/tmux differences page: mapping the command prefix to backtick instead of a ctrl key. I don't use it much in shells because I use fish, which uses parentheses instead of backticks for command substitution, so it might be a lot more convenient.