Bird
Raised Fist0
Linux CLIscripting~20 mins

tmux for persistent sessions in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Tmux Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of listing tmux sessions?
You have started two tmux sessions named work and play. What will be the output of the command tmux ls?
Linux CLI
tmux ls
A
work: 1 windows (created Wed Jun 14 10:00:00 2023) [80x24]
play: 1 windows (created Wed Jun 14 10:05:00 2023) [80x24]
B
work
play
CNo sessions found
Dtmux: command not found
Attempts:
2 left
💡 Hint
Think about how tmux shows session details with names and window counts.
💻 Command Output
intermediate
2:00remaining
What happens when you detach a tmux session?
You are inside a tmux session named dev. You run the command tmux detach. What is the immediate effect?
Linux CLI
tmux detach
AThe terminal closes immediately.
BThe tmux session is terminated and all processes inside it stop.
CYou get an error: 'detach: unknown command'
DYou exit the tmux session but it keeps running in the background.
Attempts:
2 left
💡 Hint
Detaching means leaving the session without stopping it.
📝 Syntax
advanced
2:00remaining
Which command attaches to a tmux session named 'project'?
You want to attach to an existing tmux session called project. Which command is correct?
Atmux connect project
Btmux start project
Ctmux attach -t project
Dtmux open -s project
Attempts:
2 left
💡 Hint
The attach command uses the -t option to specify the target session.
🚀 Application
advanced
2:00remaining
How to create a new tmux session named 'test' with a window running 'top'?
You want to start a new tmux session named test and immediately run the command top inside it. Which command achieves this?
Atmux new -s test 'top'
Btmux create test top
Ctmux start -n test top
Dtmux new-session -s test top
Attempts:
2 left
💡 Hint
Use the new session command with -s for session name and pass the command in quotes.
🔧 Debug
expert
2:00remaining
Why does this tmux command fail with 'unknown option' error?
You run the command tmux attach-session -d -t mysession but get an error: tmux: unknown option: -d. What is the reason?
Linux CLI
tmux attach-session -d -t mysession
AThe session 'mysession' does not exist, causing the error.
BThe -d option is not valid for attach-session; it belongs to new-session.
CYou need to run tmux as root to use the -d option.
DThe command should be run inside an existing tmux session.
Attempts:
2 left
💡 Hint
Check which commands support the -d option in tmux.

Practice

(1/5)
1. What is the main benefit of using tmux for command line sessions?
easy
A. It provides a graphical interface for Linux commands.
B. It automatically updates your system packages.
C. It allows you to keep sessions running and return to them later.
D. It replaces the need for a terminal emulator.

Solution

  1. Step 1: Understand tmux purpose

    tmux is a terminal multiplexer that lets you create, detach, and reattach sessions.
  2. Step 2: Identify main benefit

    This means you can keep your command line work running and come back anytime without losing progress.
  3. Final Answer:

    It allows you to keep sessions running and return to them later. -> Option C
  4. Quick Check:

    tmux keeps sessions persistent = A [OK]
Hint: tmux saves your work session to return anytime [OK]
Common Mistakes:
  • Thinking tmux updates software
  • Confusing tmux with GUI tools
  • Believing tmux replaces terminal emulator
2. Which of the following commands correctly creates a new named tmux session called work?
easy
A. tmux open -n work
B. tmux start work
C. tmux create session work
D. tmux new -s work

Solution

  1. Step 1: Recall tmux session creation syntax

    The correct syntax to create a named session is tmux new -s session_name.
  2. Step 2: Match command to syntax

    tmux new -s work matches this syntax exactly, creating a session named 'work'.
  3. Final Answer:

    tmux new -s work -> Option D
  4. Quick Check:

    tmux new -s name creates session = A [OK]
Hint: Use 'tmux new -s name' to start named session [OK]
Common Mistakes:
  • Using 'start' instead of 'new'
  • Omitting the '-s' flag for naming
  • Using incorrect verbs like 'create' or 'open'
3. What will be the output of the command tmux ls if you have two sessions named dev and test running?
medium
A. No sessions found
B. dev: 1 windows (created Thu Jun 1 10:00:00 2023)\ntest: 1 windows (created Thu Jun 1 10:05:00 2023)
C. Session dev attached\nSession test attached
D. Error: tmux command not found

Solution

  1. Step 1: Understand tmux ls output

    This command lists all active tmux sessions with their names and window counts.
  2. Step 2: Match output to sessions

    With two sessions 'dev' and 'test', it shows each with window count and creation time.
  3. Final Answer:

    dev: 1 windows (created Thu Jun 1 10:00:00 2023) test: 1 windows (created Thu Jun 1 10:05:00 2023) -> Option B
  4. Quick Check:

    tmux ls lists sessions = C [OK]
Hint: tmux ls lists all active sessions by name [OK]
Common Mistakes:
  • Expecting 'No sessions' when sessions exist
  • Confusing attached status with listing
  • Thinking tmux ls shows errors if tmux installed
4. You tried to reattach to a tmux session with tmux attach -t mysession but got the error: no sessions. What is the most likely cause?
medium
A. The session named 'mysession' does not exist.
B. You forgot to install tmux.
C. You need to use tmux new instead of attach.
D. The terminal emulator is not supported.

Solution

  1. Step 1: Analyze error message meaning

    The error 'no sessions' means tmux cannot find a session with the given name.
  2. Step 2: Identify cause of error

    This usually happens if the session was never created or was closed.
  3. Final Answer:

    The session named 'mysession' does not exist. -> Option A
  4. Quick Check:

    Attach error 'no sessions' means session missing = B [OK]
Hint: Check session exists before attaching [OK]
Common Mistakes:
  • Assuming tmux is not installed
  • Using attach instead of new incorrectly
  • Blaming terminal emulator
5. You want to create a tmux session named project, detach from it, and later reattach. Which sequence of commands achieves this correctly?
hard
A. tmux new -s project; Ctrl+b d; tmux attach -t project
B. tmux start project; Ctrl+c; tmux attach project
C. tmux create -n project; Ctrl+b x; tmux reattach project
D. tmux open project; Ctrl+d; tmux attach-session project

Solution

  1. Step 1: Create and detach session

    Use tmux new -s project to create session, then press Ctrl+b d to detach safely.
  2. Step 2: Reattach session

    Use tmux attach -t project to reattach to the named session later.
  3. Final Answer:

    tmux new -s project; Ctrl+b d; tmux attach -t project -> Option A
  4. Quick Check:

    Create, detach, attach with correct commands = D [OK]
Hint: Use Ctrl+b d to detach, attach with tmux attach -t name [OK]
Common Mistakes:
  • Using wrong tmux commands like start or create
  • Pressing wrong keys to detach
  • Omitting '-t' when attaching
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard