I am fairly familiar with Linux, I’ve been using different distros for some years now and have done some config editing here and there. I am also a web developer and use the terminal quite a lot and so I always stumble on people’s recommendation to use tmux and how good it is, but I never really understood what it does and, in layman’s terms, how can it be useful and for what use cases.

Can you guys please enlight me a bit on this?

Thank you.

Edit: if my phrasing is a bit awkward or confusing I apologize since I am not an English native speaker. (Maybe that’s why I never fully grasped what tmux is from other explanations xD)

Edite: Ok, just to clarify, my original struggle was to understand what made tmux different from using some terminal app and just split the screen xD

  • amyipdev@lib.lgbt
    link
    fedilink
    arrow-up
    2
    ·
    1 year ago

    Tmux is essentially an extension of the concept of running ideas in the background. Like 0xtero mentioned, you use a sort of “virtual terminal” that is persistent (unlike the jobs system you might be familiar with on your shell).

    Now, some people do just use it to split the screen. The idea is it can have multiple terminals, show them, and manage them - it is thus a “multiplexer”, which is where it gets its name (tmux = terminal multiplexer). If you’re on a terminal-only system, this isn’t that bad of a usage.

    Say you’re compiling a large program, like the Linux kernel, and you want to step away, maybe even close the terminal and come back later. Tmux is great for this. You can start the compile in tmux, “detach” (stop viewing it) from it, and it’ll still run full-speed in the background. When you want to look at it again, or check the status, you just re-attach.

  • 0xtero@kbin.social
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    I guess the best analogy is a “virtual desktop” but for the terminal.
    It’s is a program which runs in a terminal and allows multiple other terminal programs to be run inside it.

    Each program inside tmux gets its own “page” or “screen” and you can jump between them (next-screen, previous-screen etc).
    So instead of having multiple terminal windows, you only have one and switch the screen/page inside it.

    You can detech from the program and leave it running - so next time you log on to the server, you can re-attach to it and all your screens/sessions are still there.

    Not super useful on your local machine - but when you have to connect to a remote server (or several) is really shines. Especially if you have to go through a jumphost. You can just connect to your jumphost, start tmux, then create a “screen” for each server you need to connect to - do your stuff and deattach. Next time, just re-attach and all your stuff is there.

    Did that help?

    • jackofalltrades@lemmy.mlOP
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      Ok, now I guess I am seeing the value of it, specially with the “virtual desktop” analogy and the remote scenario, since I need to do some of it at work and having everything as I left it last time will be nice. Thank you!

      • topperharlie@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        1 year ago

        plus, if you disconnect in the middle of a command execution it doesn’t get killed (very important for system updates for example)

      • WasPentalive@lemmy.one
        link
        fedilink
        arrow-up
        0
        ·
        1 year ago

        I use the “being able to detach and re-attach” capability to run my Minecraft server on my in-home server box.

  • belshamharoth@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    To understand why you might want to use tmux try the following:

    1. Open your terminal
    2. Start editing a file with vim or nano but don’t save the file
    3. Close then re-open your terminal

    You will have lost your progress, next we can repeat but this time using tmux so you don’t lose your session:

    1. Open your terminal
    2. Start a tmux session using tmux
    3. Start editing a file again using vim or nano
    4. Close and re-open the terminal
    5. Type tmux a to re-attach to the existing session

    Note that this time none of your progress is lost.

    Aside from enabling you to have a persistent session, tmux also allows you to have multiple terminal panes open so you can do more than one thing at a time in the window, to see what I mean try this:

    1. Open your terminal
    2. Start a new tmux session using tmux
    3. Type top to begin listing processes
    4. Press ctrl b then % to make a new split pane
    5. Enter ls or other terminal commands

    You will see that you can use more than one panel to do things. This can be useful for example if you want to watch run tests and also run other commands.

  • Corngood@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    1 year ago

    I didn’t see this mentioned, but by far the thing I depend on tmux for the most is being able to quickly copy and paste text from the terminal. e.g. grabbing a file name from the output of git diff. How does everyone else do this?

    Another cool one is being able to attach to a session on my phone to check on something, and have it automatically resize without disconnecting my desktop.

      • Piranha Phish@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        1 year ago

        I suspect what they meant was copy and paste from the console and not a terminal.

        I don’t know how else somebody could do copy and paste at the console. And I don’t necessarily know that tmux can do this (I still haven’t graduated from ‘screen’), but this interpretation makes the most sense.

        If it can do this, presumably with just the keyboard, that’s a pretty decent feature.

        • karlthemailman@sh.itjust.works
          link
          fedilink
          arrow-up
          1
          ·
          1 year ago

          I’m not familiar with the terminology. What’s the distinction between a terminal and a console?

          Tmux does let you copy from a shell to your system clipboard using the keyboard, which is nice. But many terminal emulators like mobaxterm on windows let you copy as well.

          • Piranha Phish@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            1 year ago

            The console is the virtual terminal (VT) seen initially at boot before the desktop login starts up, or where you land if there is no desktop, and where the kernel spits its raw output. It could even be configured to be a physical serial port.

            I’m using the term in a similar manner to describe the virtual terminals spawned at boot (typically 7 of them) and occupied either by a login prompt (getty) or the desktop session, and switchable with Alt-Left/Right or using the chvt command. These are analogous to the real terminals of old such as VT100 or even typewriters.

            This is in contrast to what we normally call a terminal like xterm or Konsole which runs in the GUI where it is resizable, zoomable, etc. The console, and virtual terminals, are pretty limited in the interactivity they have. For instance, there’s no mouse interaction or copy-paste functionality, at least not without some exotic setup.

        • Corngood@lemmy.ml
          link
          fedilink
          arrow-up
          1
          ·
          1 year ago

          Yeah, doing it with the keyboard is key. I know some terminals have a way to do it, but it’s so ingrained in my muscle memory that I struggle without it, and having something that works everywhere (including try) is nice.

  • moobythegoldensock@geddit.social
    link
    fedilink
    arrow-up
    0
    ·
    1 year ago

    You’ve gotten a lot of good replies, so I’ll give you an example:

    My wife and I set up a Minecraft server on an old work computer of hers. We would SSH in, start the server, and play. However, if the host lost the SSH session, the entire server would crash because the session would close.

    With tmux, we could attach, start the server, and unattach. I could start the server and later my wife could attach to close it. I could SSH on my phone via iSH, attach, start the server, unattach, and close the app. We could troubleshoot mods together, since we could both see everything that happened in the session on our screens.

    It offered a level of flexibility a traditional SSH session doesn’t give.

      • moobythegoldensock@geddit.social
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        Minecraft is a procedurally generated open world video game.

        For multiplayer, the computer hosting the game has to be able to load the portion of the world for each player. Having a dedicated computer hosting the server allows for much smoother gameplay experience then trying to have a single PC both run the server and client.

        The machine we used for the server was literally one of my wife’s old work PCs and we just use it to host these types of games. We previously ran an ARC: Survival Evolved server on it.