Tmux could not connect to server error on `tmux ls` if no sessions are running

Just by writing a quick loop to list existing tmux sessions when logging into the server, depending on if tmux is installed (via .bashrc on CentOS).

if rpm -q tmux; then
    echo -e "TMUX sessions running:\n"
    echo `tmux ls`


This works great when tmux has a session or two, but if there are no tmux sessions running, I get failed to connect to server: No such file or directory


Is there a way to suppress this?



source to share

2 answers

Using a combination of tips from @Barmar and @Etan Reisner:

tmux ls 2> /dev/null


Doesn't repeat anything when there are no sessions, otherwise the list is reported.



Note that you can start the tmux server, but you cannot connect to it because someone cleared out the directory /tmp

and took the server socket with it.

In this case, you can tell the server to recreate the socket by sending it a SIGUSR1 signal.

% ps aux | grep -w [t]mux
root     14799  0.2  0.0  36020   488 ?        Ss   May08  51:30 tmux
% kill -USR1 14799
% tmux ls
<list of tmux sessions>




All Articles