Receipts on a server with no screen
A café's till saves every receipt as a file. The files live on a small server in the back room.
The owner asks you to copy Monday's receipts somewhere safe. The server has no screen and no mouse. You connect from a laptop and get one line to type on.
That line is all you need, once you know a few short commands.
By the end of this lesson
Note
I can move around and manage files from a command line.
Key words
| Word | What it means | Example |
|---|---|---|
| Command line | a place where you type instructions instead of clicking | |
| Command | one instruction, sent when you press Enter | pwd |
| Folder | a place that holds files and other folders | |
| Path | the address of a file or folder | /home/student/projects |
| Working directory | the folder you are in now | |
| Home folder | the folder that belongs to you | ~ |
The cells students fill in are left blank in this preview.
Before you start
Note
Press Start the lab on the bar at the top. The lab is a whole Ubuntu machine of your own, so it takes a minute to start. Each Run button types its command into your terminal. Press the Runs in order, because each one carries on from the last.
A path is the address of a file
The command line is always "in" one folder, the working directory. pwd prints it.
A path that starts with / is a full path. It works from anywhere.
A path with no / at the start is a relative path. The machine looks for it inside the folder you are in. cd moves you to another folder. cd .. goes up one folder.
Worked example: where cd takes you
| You are in | You type | You end up in |
|---|---|---|
| /home/student | cd projects | /home/student/projects |
| /home/student/projects | cd docs | /home/student/projects/docs |
| /home/student/projects/docs | cd .. | /home/student/projects |
| /home/student/projects | cd /var/log | /var/log |
| /var/log | cd projects | An error: no such folder here |
The cells students fill in are left blank in this preview.
Which folder am I in?
pwdShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
What is in this folder?
lsShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Go down two folders
cd projects/docsShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Where am I now?
pwdShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
A common mistake
Warning
Many people think cd projects works from any folder. It only looks inside the folder you are in now. If you see "No such file or directory", run pwd first. Or type a full path that starts with /.
mkdir, cp and mv change files
mkdir -p makes a folder, and any missing folder above it. cp copies a file and leaves the original where it was. mv moves a file. Give it a new name in the same folder and it renames the file.
rm removes a file. A server has no bin, so a removed file is gone.
The first Run below takes you home again.
Go back to your home folder
cdShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Make a folder for receipts
mkdir -p shop/receiptsShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Copy a file into it
cp projects/docs/notes.txt shop/receipts/monday.txtShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Rename the copy
mv shop/receipts/monday.txt shop/receipts/tuesday.txtShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Look inside the new folder
ls shop/receiptsShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Going further
Type these yourself. Make a folder old inside shop. Copy tuesday.txt into it with the new name wednesday.txt.
Then run ls -R shop. It lists a folder and every folder inside it. Say what it will print before you press Enter.