As a Linux power user, I've found GNU screen to be indispensable for managing terminal sessions. Beyond basic session persistence, it offers powerful features most developers overlook. Let's dive into the most useful hidden capabilities.
Few realize screen can share sessions between users. Perfect for pair programming or debugging:
# Start a named session with multi-user permissions
screen -S shared_session
ctrl+a :multiuser on
ctrl+a :acladd username2
While tmux popularized vertical splits, screen can do it too with some configuration:
# In .screenrc:
layout new
split -v
focus
screen
focus
screen
Most use basic scrollback, but screen offers sophisticated buffer operations:
# Search buffer history (like less)
ctrl+a [ # enter copy mode
/pattern # search forward
?pattern # search backward
# Save buffer to file
ctrl+a :hardcopy -h buffer.txt
Customize startup behavior with these powerful .screenrc examples:
# Auto-startup commands
screen -t shell1 0
screen -t shell2 1 ssh user@server
screen -t logs 2 tail -f /var/log/syslog
# Custom status bar
hardstatus alwayslastline "%{=b kg}%H %{= kw}%c %{=b kg}%-w%{=b bw}%n %t%{-}%+w"
Get alerts when activity occurs in background sessions:
# Monitor for activity
ctrl+a :monitor on
# Visual bell when activity detected
vbell on
vbell_msg "Activity in window %n: %t"
Secure your sessions with encryption:
# In .screenrc:
password ODSJKE9324JFWEFJ
Beyond basic window switching:
# Name current window
ctrl+a A
# Reorder windows
ctrl+a :number 3 # move current window to position 3
# Window groups for organization
ctrl+a :groupname Dev
Even in the age of tmux and cloud terminals, GNU screen continues to be the Swiss Army knife for terminal multiplexing. Its true power lies in obscure features that most developers never discover. Let's dive into the most valuable hidden gems.
Ever lost work after a network dropout? Try this:
screen -S projectx -d -m # Start detached session screen -r projectx # Reattach later
The -d -m
combo creates a persistent session that survives disconnections. Combine with autodetach
in your .screenrc
:
autodetach on defdetach on
Beyond basic splits, screen can:
- Rotate window layouts with
C-a C-o
- Create vertical splits with
split -v
- Focus regions without mouse using
C-a TAB
The copy mode (C-a [
) has powerful extensions:
# Search backward in history C-a [ ?keyword # Pipe buffer directly to a file C-a : hardcopy -h /path/to/log.txt
Customize your status line with dynamic info:
hardstatus alwayslastline "%{= kG}%-w%{= BW}%n %t%{-}%+w %=%d/%m %c"
This shows window list with colors and adds clock - try adding CPU load with %l
.
Chain SSH connections while keeping sessions alive:
screen -t gateway ssh user@jumphost # Inside that window: ssh -t internal-server screen -xS project
The -t
flag preserves pseudo-terminals across hops.
Pair programming made easy:
screen -S shared -x # Multiuser attach
Set permissions in .screenrc
:
multiuser on acladd teammate
Advanced logging that rotates files:
# In .screenrc: logfile /path/to/screenlog.%n logfile flush 1 log on
Then toggle logging per window with C-a H
.