RANGEZERO

Learn / Linux Fundamentals / Shell Basics

Navigating the Shell

guidedeasy 25 min · 95 points

First Bit is still up for grabs: be the first to finish this room.

The terminal can feel like a dark room at first. This room gives you a flashlight: three commands (pwd, ls and cd) that tell you where you are, what's around you, and how to move.

Every answer here can be worked out from the text, but you'll learn it faster if you open a terminal on any Linux machine (or WSL on Windows, or Terminal on macOS) and try each command as you read.

CYB//RANGE Live lab

Log in to launch this room's lab.

Task 1 Where am I?

Every shell session has a current directory: the folder your commands act on unless you say otherwise. To find out where you are, use pwd:

$ pwd
/home/ada

/home/ada is Ada's home directory. Each user gets one, and a new terminal usually starts there. It's so common that the shell has a one-character shorthand for it: ~. When you see a prompt like ada@box:~$, the ~ means "you're at home".

ada@box:~$ pwd
/home/ada

Which command prints the directory you are currently in?

Log in or sign up to answer. 10 pts

***

Which single character is the shell's shorthand for your home directory?

Log in or sign up to answer. 5 pts

*

Task 2 Looking around

ls lists what's in the current directory:

$ ls
notes  projects  todo.txt

That's not everything. Files and directories whose names start with a dot are hidden: plain ls skips them. They're usually settings you don't want cluttering every listing. Add -a (or --all) to see them, and -l for the long format:

$ ls -la
total 28
drwxr-x--- 5 ada ada 4096 Sep 20 09:12 .
drwxr-xr-x 4 root root 4096 Sep 01 08:00 ..
-rw-r--r-- 1 ada ada 3771 Sep 01 08:00 .bashrc
drwx------ 3 ada ada 4096 Sep 15 17:41 .ssh
drwxr-xr-x 2 ada ada 4096 Sep 20 09:12 notes
drwxr-xr-x 4 ada ada 4096 Sep 18 14:03 projects
-rw-r--r-- 1 ada ada  112 Sep 19 21:30 todo.txt

The first character of each line tells you the type: d is a directory, - is a regular file. Security people care about hidden files: .ssh holds SSH keys, and .bashrc runs every time the user opens a shell, which makes it a favourite place for attackers to hide a backdoor.

A file is hidden from a plain ls when its name starts with which character?

Log in or sign up to answer. 5 pts

*

Which option makes ls show hidden files too? (Short or long form.)

Log in or sign up to answer. 10 pts

**

In the example listing, what is the name of the hidden file that is not a directory?

Log in or sign up to answer. 10 pts

*******

Task 3 Moving around

cd changes your current directory. You can give it two kinds of path:

  • An absolute path starts at the root of the filesystem, /, and spells out every step: cd /home/ada/projects. It works from anywhere.
  • A relative path starts from where you are now: from /home/ada, cd projects takes you to /home/ada/projects.

Two special names make relative paths powerful:

Name Means
. this directory
.. the parent directory, one level up

So from /home/ada/projects/web, cd .. takes you to /home/ada/projects, and each extra ../ climbs another level.

Two more shortcuts: cd with no argument takes you home (~), and cd - jumps back to wherever you were just before, which is handy when you're bouncing between two folders.

$ cd /var/log
$ cd ~/projects
$ cd -
/var/log

An absolute path always starts with which character?

Log in or sign up to answer. 5 pts

*

Which two characters stand for the parent directory (one level up)?

Log in or sign up to answer. 5 pts

**

You are in /home/ada/projects/web and run cd ../../notes. What does pwd print now? (Full path.)

Log in or sign up to answer. 15 pts

/****/***/*****

Which cd argument takes you back to the directory you were in just before?

Log in or sign up to answer. 10 pts

*

Task 4 Try it on a real machine

Reading about the shell only gets you so far. This room comes with a real Linux machine: Ada's computer, box.

  1. Press Launch in CybRange at the top of this page. Your machine is ready in about a minute.
  2. Press Open terminal next to box. You're logged in as ada, in her home directory.
  3. Try everything from the tasks above: pwd, ls, ls -la, cd projects, cd .., cd -. Nothing you do here can break anything. When the lab ends the machine is thrown away, and your next launch starts fresh.

Ada has been keeping a secret in her projects folder. Find it.

Somewhere in Ada's projects folder is a hidden file. What flag does it hold?

Log in or sign up to answer. 20 pts

RZ{************************}