Where you are, and files

INPUT · Slides

Make it, move it, remove it

01 / 08

Make a box — mkdir

The command that makes a new directory (a box) is mkdir, short for make directory.

Just write the name you want after it. When it works you get, as usual, nothing on the screen. Check with ls.

~ $ mkdir diary~ $ lsdiary

02 / 08

Make an empty file — touch

To make a file with nothing in it, use touch.

It was originally there to set the time on a file to now, but hand it the name of a file that does not exist and it makes one, so this is the use you see far more often.

~ $ touch memo.txt~ $ lsdiary  memo.txt

03 / 08

Make it deep in one go — mkdir -p

Try to make something inside a box that does not exist yet, like mkdir diary/2026, and it turns you down.

When that happens, add -p. It is the option that makes the boxes along the way if they are missing.

~ $ mkdir diary/2026mkdir: cannot create directory 'diary/2026': No such file or directory~ $ mkdir -p diary/2026

04 / 08

Remove it — rm and rmdir

Files come off with rm (remove), and empty boxes come off with rmdir.

Here is the most important thing in this lesson. What rm removes does not go to a wastebasket. You cannot undo it.

It does not even ask. So let us get the habit into your fingers here, in this safe room. Press "start over" and you can go again as many times as you like.

~ $ rm memo.txt~ $ rmdir empty

05 / 08

Remove it, contents and all — rm -r

rmdir only removes empty boxes. Put anything inside and it refuses.

When you want the contents gone too, use rm -r. The -r means "follow it down inside". It is powerful, so get into the habit of running ls to see what is in there before you type it.

~ $ rmdir diaryrmdir: 'diary': Directory not empty~ $ rm -r diary

06 / 08

Move it, rename it — mv

mv (move) is a slightly odd command that does two jobs with one name.

  • mv old.txt new.txt — rename it
  • mv memo.txt diary/ — move it into another box

Both of them are "put it down again, under that name, in that place", so Linux treats them as the same operation.

~ $ mv old.txt new.txt~ $ mv new.txt diary/

07 / 08

Copy it — cp

cp (copy) makes a duplicate and leaves the original where it was. Whether the original survives is the only difference from mv.

When you want to copy a whole box, add -r, same as with rm.

~ $ cp memo.txt copy.txt~ $ cp -r diary diary-backup

08 / 08

Now go and make something

From here you make things yourself.

Get into the habit of checking with ls afterwards. Nothing on the screen means it worked, but seeing it with your own eyes is more reassuring.

Some of the questions ask you to remove things, but this room is disposable. Break it and "start over" brings it all back.