RANGEZERO

Learn / Linux Fundamentals / Shell Basics

Files and Folders

guidedeasy 30 min · 100 points

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

In Navigating the Shell you learned to look around. Now you'll change things: create folders and files, copy and move them, rename them, delete them, and use wildcards so one command can act on dozens of files at once.

This room comes with a real machine. When you reach the last task, launch it and practise everything on Ben's messy downloads folder.

CYB//RANGE Live lab

Log in to launch this room's lab.

Task 1 Making things

mkdir ("make directory") creates a folder:

$ mkdir reports
$ ls
reports

To create a folder inside folders that don't exist yet, add -p ("parents"). Without it, mkdir refuses:

$ mkdir photos/2026/july
mkdir: cannot create directory 'photos/2026/july': No such file or directory
$ mkdir -p photos/2026/july

touch creates an empty file. If the file already exists, it leaves the contents alone and just updates the file's "last modified" time:

$ touch notes.txt
$ ls -l notes.txt
-rw-r--r-- 1 ben ben 0 Sep 30 10:15 notes.txt

That 0 is the size in bytes: the file exists, but it's empty.

Which command creates a new directory?

Log in or sign up to answer. 5 pts

*****

Which option lets mkdir create any missing parent directories along the way? (Short or long form.)

Log in or sign up to answer. 10 pts

**

Which command creates an empty file (or, if the file exists, just updates its timestamp)?

Log in or sign up to answer. 5 pts

*****

Task 2 Copying, moving and renaming

cp copies: first what to copy, then where to put it.

$ cp notes.txt notes-backup.txt       # a copy with a new name
$ cp notes.txt reports/               # a copy inside another folder

Folders need -r ("recursive": the folder and everything inside it, all the way down):

$ cp reports archive/
cp: -r not specified; omitting directory 'reports'
$ cp -r reports archive/

mv moves, with the same "from, to" order. There's no copy left behind:

$ mv notes-backup.txt reports/

Moving a file to a new name in the same place is renaming, so mv is also how you rename:

$ mv draft.txt final.txt

Careful: if the destination file already exists, both cp and mv overwrite it without asking. Add -i ("interactive") and they'll ask first.

Which option makes cp copy a directory and everything inside it? (Short or long form.)

Log in or sign up to answer. 10 pts

**

Linux has no separate rename command for everyday use. Which command renames a file?

Log in or sign up to answer. 10 pts

**

Task 3 Deleting, and wildcards

rm deletes files. There's no recycle bin: a file removed with rm is gone.

$ rm old-notes.txt
$ rm -r old-reports/        # a folder and everything in it
$ rm -i *.log               # -i asks about each file first

(rmdir also removes a folder, but only an empty one, which makes it the safer choice when that's what you expect.)

Wildcards let you name many files at once. The shell expands them into the matching file names before the command runs:

Wildcard Matches Example Matches
* any number of characters, even none *.jpg a.jpg, photo-01.jpg
? exactly one character photo-0?.jpg photo-01.jpg, not photo-10.jpg
[...] one character from the set photo-0[1-3].jpg photo-01.jpg to photo-03.jpg

So mv *.jpg photos/ moves every JPEG in one go, and ls */*.txt lists the text files one folder down.

Try echo *.jpg to see what a wildcard expands to before you point rm at it.

Which wildcard matches any number of characters (including none)?

Log in or sign up to answer. 5 pts

*

Which wildcard matches exactly one character?

Log in or sign up to answer. 5 pts

*

Write a pattern that matches every file in the current directory whose name ends in .txt.

Log in or sign up to answer. 10 pts

*****

Task 4 Try it on a real machine

Ben's downloads folder is a mess, and his archive has a folder for every month. Let's sort it out on his real machine.

  1. Press Launch in CybRange at the top of this page. The machine is ready in about a minute.
  2. Press Open terminal next to box. You're logged in as ben, in his home folder.
  3. Look around: ls, ls downloads, ls archive.

Some things to try (nothing here can break anything; each launch starts fresh):

  • Make a tidy home for the photos: mkdir -p ~/sorted/photos
  • Move them all at once: mv ~/downloads/*.jpg ~/sorted/photos/
  • Copy the invoices somewhere safe: mkdir ~/sorted/invoices then cp ~/downloads/invoice-* ~/sorted/invoices/
  • Rename notes.txt to readme.txt with mv
  • Delete the song: rm ~/downloads/song.mp3

Then answer the questions below. The last one needs a wildcard that stands in for a folder name.

How many invoice files are in ~/downloads?

Log in or sign up to answer. 10 pts

*

The photos should run from photo-01.jpg to photo-08.jpg, but one is missing. Which number? (Two digits.)

Log in or sign up to answer. 10 pts

**

Somewhere in ~/archive there is exactly one file whose name ends in .flag. What flag is inside it?

Log in or sign up to answer. 20 pts

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