0
0
Linux CLIscripting~20 mins

Home directory (~) and shortcuts in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Tilde Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this command?
Consider the command echo ~ executed by user alice. What will it output?
Linux CLI
echo ~
A/home/alice
B~
C/root
D/home
Attempts:
2 left
💡 Hint
The tilde (~) expands to the current user's home directory.
💻 Command Output
intermediate
2:00remaining
What does this command output?
What is the output of echo ~root when run by a normal user?
Linux CLI
echo ~root
A/root
B~root
C/home/root
DError: user not found
Attempts:
2 left
💡 Hint
The shell expands ~username to that user's home directory if it exists.
📝 Syntax
advanced
2:00remaining
Which command correctly changes directory to the home directory of user 'bob'?
You want to change directory to user bob's home using a shortcut. Which command is correct?
Acd ~ /bob
Bcd ~/bob
Ccd ~bob
Dcd ~bob/
Attempts:
2 left
💡 Hint
The tilde followed immediately by username expands to that user's home directory.
🧠 Conceptual
advanced
2:00remaining
What does the shortcut ~+ represent in the shell?
In bash and similar shells, what does the shortcut ~+ expand to?
AThe root directory
BThe previous working directory
CThe current working directory
DThe home directory
Attempts:
2 left
💡 Hint
Think about what the shell variable PWD holds.
💻 Command Output
expert
2:00remaining
What is the output of this command sequence?
Given the commands run in order:
cd /tmp
echo ~-
What will be printed?
Linux CLI
cd /tmp
echo ~-
A/
B/home/alice
C/tmp
D~-
Attempts:
2 left
💡 Hint
The shortcut ~- expands to the previous working directory.