0
0
Linux CLIscripting~20 mins

cd (change directory) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of cd command
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 sequence of commands?
Assume you start in your home directory /home/user. You run these commands:

cd /var/log
cd ../lib
pwd

What is the output of pwd?
Linux CLI
cd /var/log
cd ../lib
pwd
A/var/lib
B/var/log/lib
C/var/log
D/home/user/lib
Attempts:
2 left
💡 Hint
Remember that .. moves one directory up from the current location.
💻 Command Output
intermediate
1:30remaining
What happens when you run cd -?
You start in /home/user, then run cd /etc. Next, you run cd -. What directory will you be in after the last command?
Linux CLI
cd /home/user
cd /etc
cd -
pwd
A/home/user
B/etc
C/
DError: no previous directory
Attempts:
2 left
💡 Hint
cd - switches to the previous directory you were in.
💻 Command Output
advanced
1:00remaining
What error does this command produce?
You run this command:

cd /nonexistent/path

What error message will the shell show?
Linux CLI
cd /nonexistent/path
Abash: cd: command not found
Bbash: cd: permission denied
Cbash: cd: /nonexistent/path: No such file or directory
DNo error, directory changed
Attempts:
2 left
💡 Hint
Think about what happens if you try to go to a folder that does not exist.
💻 Command Output
advanced
1:30remaining
What is the output of this command sequence involving symbolic links?
Assume /tmp/link is a symbolic link to /var/log. You run:

cd /tmp/link
pwd -P

What is the output?
Linux CLI
cd /tmp/link
pwd -P
A/tmp/link
B/var/log
C/tmp
DError: pwd command not found
Attempts:
2 left
💡 Hint
The -P option shows the physical directory, resolving symbolic links.
🚀 Application
expert
2:30remaining
How many directories deep is the final location?
Starting at /home/user, you run:

cd ../../etc/../var/./log/../lib

How many directories deep is the final directory from the root /? (Count each directory level in the path)
Linux CLI
cd ../../etc/../var/./log/../lib
pwd
A5
B2
C4
D3
Attempts:
2 left
💡 Hint
Simplify the path step by step, removing . and resolving ...