Tech C**P
14 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal.
after installation you can list your sessions by:
tmux ls

Output would be something like this:
0: 1 windows (created Mon Aug  7 10:34:00 2017) [135x52] (attached)
2: 1 windows (created Mon Aug 7 13:56:10 2017) [126x25]

(attached) at the end of session 0 tells us that the session has been attached by a user.
You can attach a session by:
tmux attach -t 0
-t tells tmux which session should be attached.

Now let's say you want to detach a session you need to press ^b+d (CONTROL+b and then press d).

If you want to split your window to multiple panes press ^b+" (split horizontally) and/or ^b+% (split vertically).

^b+n : next window
^b+(up/down/left/right) : to move between panes
^b+? : help and shortcuts
^b+x : kill a pane

THE GREAT THING about tmux is that multiple users can attach the same session and work simultaneously!

I know you will get tired if I say more about tmux, so go and explore more yourself and see the real power of multiplexers.

#tmux #linux #sysadmin #terminal #multiplexer
Migrate a running process into tmux

reptyr is a utility for taking an existing running program and attaching it to a new terminal. Started a long-running process over ssh, but have to leave and don’t want to interrupt it? Just start a screen, use reptyr to grab it, and then kill the ssh session and head on home.

sudo apt-get install -y reptyr    # For Ubuntu users

Send the current foreground job to the background using CTRL-Z.

List all the background jobs using jobs -l. This will get you the PID.

jobs -l
[1] + 16189 suspended vim foobar.rst


Here the PID is 16189.
Start a new tmux or screen session. I will be using tmux:

tmux


Reattach the background process using:

reptyr 16189

If this error appears:

Unable to attach to pid 16189: Operation not permitted
The kernel denied permission while attaching


Then type in the following command as root.

echo 0 > /proc/sys/kernel/yama/ptrace_scope

#reptyr #tmux #screen #pid
To rename a window in tmux, press Control+b then press comma as below:

^b + ,

Now you can edit your window name and hit enter to save the new name.

#tmux #window