Learn / Linux Fundamentals / Shell Basics
Files and Folders
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.
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.
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.
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.
- Press Launch in CybRange at the top of this page. The machine is ready in about a minute.
- Press Open terminal next to
box. You're logged in asben, in his home folder. - 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/invoicesthencp ~/downloads/invoice-* ~/sorted/invoices/ - Rename
notes.txttoreadme.txtwithmv - 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.