Step 1.5 · Ubuntu · Nothing to install

Finding your way around

You have a terminal open. Before installing anything into it, learn to move around, and to make, read and remove files. Every later step assumes you can do this — step 3 will simply say “create hello.c” and expect you to know how.

There is no command to run for this step

Everything here is already on your machine. These commands come with Ubuntu itself, which is why no installer is needed. Just work through the page, typing as you go — twenty minutes is enough.

Where am I?

A terminal is always sitting somewhere in the filesystem. This tells you where.

$ pwd
/home/yourname

pwd means print working directory. That /home/yourname is your home folder — where you start, and where your own files belong.

What is in here?

$ ls

A fresh account has almost nothing, so that may print nothing at all. Ask for more detail:

$ ls -l

And to include hidden files:

$ ls -la
Hidden files start with a dot

.bashrc is hidden. There is nothing secret about it — Linux simply treats any name beginning with . as something to keep out of the way, because these are settings files you rarely need to see. That is the same .bashrc the installers add lines to.

Moving around

Go into a folder:

$ cd /etc

Look at where you landed:

$ pwd

Go back up one level, towards the top of the tree:

$ cd ..

Go straight home from anywhere:

$ cd ~

Or plain cd on its own, which does the same thing:

$ cd

The four symbols worth learning now

SymbolMeansExample
.the folder I am in right now./hello
..the folder above this onecd ..
~my home foldercd ~
/the very top of the treecd /

A path that starts with / says exactly where something is, from the top: /home/yourname/notes. A path that does not is read from wherever you currently are: notes means “the notes folder here”.

One tree, no drive letters

Windows has C: and D:. Linux has a single tree starting at /, and everything — including your Windows drive, at /mnt/c — hangs somewhere inside it.

Making folders and files

Make a folder:

$ mkdir practice

Go into it:

$ cd practice

Make a folder and any parent folders it needs, in one go:

$ mkdir -p notes/january

Create an empty file:

$ touch hello.txt

Put a line of text into a file:

$ echo "my first line" > hello.txt

Add another line to the end of it:

$ echo "a second line" >> hello.txt
> replaces, >> adds

echo normally prints to the screen. > sends that text into a file instead — throwing away whatever the file held before. >> adds to the end and keeps what was there. One extra character, and a great deal of difference.

That is enough for a line or two. For writing a real file you want an editor, and nano arrives in step 2.

Reading a file

Print the whole thing:

$ cat hello.txt
my first line
a second line

Just the first few lines — useful when a file is long. /etc/passwd is a real system file listing the accounts on this machine, so there is something to look at:

$ head -n 5 /etc/passwd

Or the last few lines — your own account will be near the bottom:

$ tail -n 3 /etc/passwd
Two more file tools arrive in step 2

less, for paging through something too long for one screen, and nano, for editing a file properly, are not on a fresh Ubuntu. Step 2 installs both. Until then cat, head and tail are enough.

Copying and renaming

Copy a file:

$ cp hello.txt backup.txt

Copy a whole folder and everything inside it:

$ cp -r notes notes-backup

Rename something:

$ mv backup.txt old-hello.txt

Move it into a folder:

$ mv old-hello.txt notes/
Renaming and moving are the same thing

There is no separate rename command. mv changes where something is and what it is called — and those turn out to be the same question.

Deleting

There is no Recycle Bin

rm does not move a file anywhere. It removes it, immediately and permanently. There is no undo, and nothing to restore from.

Read the whole line before pressing Enter — especially when it contains -r or a *.

Delete a file:

$ rm old-hello.txt

Delete an empty folder:

$ rmdir notes/january

Delete a folder and everything inside it:

$ rm -r notes-backup

Ask before each deletion — a good habit while you are learning:

$ rm -ri notes-backup

Four keys that save you

Tab is not a shortcut, it is the way

Experienced people almost never type a full filename. They type three letters and press Tab. If Tab does not complete, the name is wrong or you are in the wrong folder — which makes it a spell-checker as well.

Practice

Work through these in order. Together they build a small tree, look at it, and take it apart again.

$ cd ~
$ mkdir -p practice/notes
$ cd practice
$ echo "day one" > notes/day1.txt
$ echo "day two" > notes/day2.txt
$ ls -l notes
$ cat notes/day1.txt
$ cp notes/day1.txt notes/day1-copy.txt
$ mv notes/day1-copy.txt notes/day3.txt
$ pwd

Now take it all away again:

$ cd ~
$ rm -r practice
$ ls

Your Windows files

If you are on WSL, your Windows drive is inside this same tree, under /mnt/c. Have a look, but do not work there:

$ ls /mnt/c/Users

Files under /mnt/c are reached through a translation layer and are much slower to work with. Keep your own work in your home folder — step 1 explains why.

Want to know why it is built this way?

Chapter 2 of the book explains the ideas behind these commands: why Linux has one tree and no drive letters, what a path really is, and why a deleted file cannot come back.

Before moving on

You should now be able to do all of these without looking them up:

If any of those is still shaky, run through the practice section once more. Everything after this point assumes them.