tmux
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesetmux
tmux
Terminal multiplexer for background processes, output capture, and session management.
用于后台进程管理、输出捕获和会话管理的终端复用工具。
Quick Reference
快速参考
| Command | Description |
|---|---|
| Run command in background session |
| Capture output from session |
| Send input to session |
| Terminate session |
| List all sessions |
| Check if session exists |
| 命令 | 说明 |
|---|---|
| 在后台会话中运行命令 |
| 捕获会话中的输出 |
| 向会话发送输入内容 |
| 终止会话 |
| 列出所有会话 |
| 检查会话是否存在 |
Running Background Processes
运行后台进程
bash
undefinedbash
undefinedRun command in new detached session
在新的分离会话中运行命令
tmux new-session -d -s myserver 'python -m http.server 8080'
tmux new-session -d -s myserver 'python -m http.server 8080'
With specific working directory
指定工作目录
tmux new-session -d -s build -c /path/to/project 'make build'
tmux new-session -d -s build -c /path/to/project 'make build'
Keep session alive after command completes
命令执行完成后保持会话活跃
tmux new-session -d -s task 'command; exec bash'
tmux new-session -d -s task 'command; exec bash'
Run only if session doesn't exist
仅在会话不存在时运行
tmux has -t myserver || tmux new-session -d -s myserver 'command'
undefinedtmux has -t myserver || tmux new-session -d -s myserver 'command'
undefinedCapturing Output
捕获输出
bash
undefinedbash
undefinedCapture visible output
捕获可见输出
tmux capture-pane -t mysession -p
tmux capture-pane -t mysession -p
Capture entire scrollback history
捕获整个回滚历史
tmux capture-pane -t mysession -p -S -
tmux capture-pane -t mysession -p -S -
Capture last N lines
捕获最后N行内容
tmux capture-pane -t mysession -p -S -100
tmux capture-pane -t mysession -p -S -100
Save to file
保存到文件
tmux capture-pane -t mysession -p > output.txt
tmux capture-pane -t mysession -p > output.txt
Capture with escape sequences (colors)
捕获包含转义序列(颜色)的输出
tmux capture-pane -t mysession -p -e
undefinedtmux capture-pane -t mysession -p -e
undefinedSending Input
发送输入
bash
undefinedbash
undefinedSend text and Enter
发送文本并执行(按下回车)
tmux send-keys -t mysession 'echo hello' Enter
tmux send-keys -t mysession 'echo hello' Enter
Send without Enter
发送文本但不执行
tmux send-keys -t mysession 'some-text'
tmux send-keys -t mysession 'some-text'
Send Ctrl+C
发送Ctrl+C
tmux send-keys -t mysession C-c
undefinedtmux send-keys -t mysession C-c
undefinedSession Management
会话管理
bash
undefinedbash
undefinedList sessions
列出会话
tmux list-sessions
tmux ls
tmux list-sessions
tmux ls
Kill specific session
终止指定会话
tmux kill-session -t myserver
tmux kill-session -t myserver
Kill all sessions
终止所有会话
tmux kill-server
tmux kill-server
Check if session exists
检查会话是否存在
tmux has -t mysession
undefinedtmux has -t mysession
undefinedWait for Completion
等待任务完成
bash
undefinedbash
undefinedSignal completion from command
从命令发送完成信号
tmux new-session -d -s job 'command; tmux wait-for -S job-done'
tmux new-session -d -s job 'command; tmux wait-for -S job-done'
Wait for signal
等待完成信号
tmux wait-for job-done
undefinedtmux wait-for job-done
undefinedCommon Patterns
常见使用模式
Development Servers
开发服务器
bash
tmux new-session -d -s backend 'bun run backend'
tmux new-session -d -s frontend 'bun run frontend'
tmux new-session -d -s tests 'vitest --watch'bash
tmux new-session -d -s backend 'bun run backend'
tmux new-session -d -s frontend 'bun run frontend'
tmux new-session -d -s tests 'vitest --watch'Run and Capture Output
运行并捕获输出
bash
tmux new-session -d -s job 'command'
sleep 0.5
output=$(tmux capture-pane -t job -p)
echo "$output"bash
tmux new-session -d -s job 'command'
sleep 0.5
output=$(tmux capture-pane -t job -p)
echo "$output"Conditional Session
条件式创建会话
bash
tmux has -t myserver || tmux new-session -d -s myserver 'command'bash
tmux has -t myserver || tmux new-session -d -s myserver 'command'Cleanup
清理会话
bash
tmux kill-session -t backend
tmux kill-session -t frontend
tmux kill-server # Kill allbash
tmux kill-session -t backend
tmux kill-session -t frontend
tmux kill-server # 终止所有会话Tips
小贴士
- Use for background processes
tmux new-session -d - Use for full scrollback
tmux capture-pane -p -S - - Use to check session existence
tmux has -t name - Use to clean up all sessions
tmux kill-server - Use to set working directory
-c /path - Use to keep session alive after command
exec bash
- 使用来运行后台进程
tmux new-session -d - 使用来捕获完整的回滚历史
tmux capture-pane -p -S - - 使用来检查会话是否存在
tmux has -t name - 使用来清理所有会话
tmux kill-server - 使用来设置工作目录
-c /path - 使用在命令执行完成后保持会话活跃
exec bash