Section 1

1 Before you start

This is not graded, and it does not count towards anything. Answer every question even if you are only guessing — having a go at something before you have been taught it is one of the best ways to remember it afterwards. The lesson ends with another short check, and there you will be shown the correct answer for anything you missed. Choose an option for every question and confidence rating, then click Submit answers.

Pre-test

Which command creates a new, empty file called patient_001.txt?

Pre-test

You want to create the folder study/raw/vitals in one step, even though study/ does not exist yet. Which command works?

Pre-test

What is the difference between cp and mv?

Pre-test

Which command renames the file draft.csv to cohort_2026.csv?

Pre-test

After running rm important.csv, how do you get the file back?

Pre-test

Which command removes an EMPTY directory?

Pre-test

What does the -i flag add to commands like rm, cp, and mv?

Pre-test

You want to copy a folder and everything inside it. Which command works?

Pre-confidence

I can create folders and empty files from the terminal.

Not at all confident
Fully confident
Pre-confidence

I can copy and move files, and I know which command keeps the original.

Not at all confident
Fully confident
Pre-confidence

I know why rm should be used carefully and what -i does.

Not at all confident
Fully confident
Section 2

2 Introduction

Now that you can move around, the next step is to create, copy, move, and delete things. These are everyday commands - you will use them every time you sit at a terminal. The commands are short, but a couple are unforgiving, so we will cover the safety rails too.

  • Making new folders and empty files: mkdir, touch.
  • Copying and moving: cp, mv (and renaming).
  • Removing: rm, rmdir, and why deletion in the terminal is permanent.
  • Useful flags: -r recursive, -i interactive, -v verbose.
Section 3

3 Making New Folders - mkdir

mkdir creates a folder in the current location:

$ pwd
/home/student
$ mkdir cohort_2026
$ ls
big_cohort.csv  cohort.csv  cohort_2026  cohort_2026.csv  cohort_summary.sh
convert_ecg_all.sh  notes.txt  patients.json  scripts  vitals

List several folders in one command to create them all:

$ mkdir raw_vitals cleaned_vitals lab_reports figures

To create a folder AND any missing parents in one go, add -p. Without -p, mkdir refuses to create nested folders if a step in the middle does not exist.

$ mkdir cohort_2026/raw/vitals
mkdir: cannot create directory 'cohort_2026/raw/vitals': No such file or directory
$ mkdir -p cohort_2026/raw/vitals
$ ls cohort_2026/raw
vitals
Try it out

Try this snippet in the Bash Scratchpad on the right.

Try this snippet
$ mkdir test_folder
$ ls
$ mkdir -p study/raw/vitals
$ ls study/raw
mkdir makes one folder per name you pass it, so several names create several folders at once, and a nested path only succeeds when every parent already exists, which is exactly the gap -p closes by creating each missing level along the path.
mkdir makes one folder per name you pass it, so several names create several folders at once, and a nested path only succeeds when every parent already exists, which is exactly the gap -p closes by creating each missing level along the path.
Section 4

4 Making Empty Files - touch

touch creates an empty file. If the file already exists, touch leaves the contents alone and just updates the timestamp - occasionally useful in scripts. For now, think of touch as "make a new empty file".

$ touch patient_001.txt
$ ls -lh patient_001.txt
-rw-r--r-- 1 student staff 0 May 24 11:03 patient_001.txt
Running touch with a filename brings a brand-new file into existence that contains nothing at all (0 bytes), and ls -lh confirms it is there with a size of zero.
Running touch with a filename brings a brand-new file into existence that contains nothing at all (0 bytes), and ls -lh confirms it is there with a size of zero.

The 0 in the size column confirms the file is empty. You can pass several filenames at once.

Try it out

Try this snippet in the Bash Scratchpad on the right.

Try this snippet
$ touch a.txt b.txt c.txt
$ ls -lh
Section 5

5 Copying and Moving - cp and mv

Once a file exists, you often want a second copy of it or need it in a different place. For example, you might keep a backup of a data file before cleaning it, put raw files into the right folder, or fix a file name. Two commands do this work: cp makes a copy, and mv moves a file or folder.

Section 5.1

5.1 cp - make a copy

The shape is always cp SOURCE DESTINATION. The source exists; the destination is where the copy lands.

$ cp cohort_2026.csv cohort_2026_backup.csv
$ ls
big_cohort.csv  cohort.csv  cohort_2026.csv  cohort_2026_backup.csv  cohort_summary.sh
convert_ecg_all.sh  notes.txt  patients.json  scripts  vitals

If the destination is a folder, the copy lands inside it with the original name:

$ mkdir archive
$ cp cohort_2026.csv archive/
$ ls archive
cohort_2026.csv

To copy a whole folder you must add -r (recursive):

$ cp vitals vitals_backup
cp: -r not specified, omitting directory 'vitals'
$ cp -r vitals vitals_backup
$ ls
big_cohort.csv  cohort.csv  cohort_2026.csv  cohort_summary.sh  convert_ecg_all.sh
notes.txt  patients.json  scripts  vitals  vitals_backup
The command is always cp SOURCE DESTINATION and the source is never touched; a plain destination makes a renamed copy, a folder destination drops the copy inside under its original name, and copying a folder requires -r so its contents come along.
The command is always cp SOURCE DESTINATION and the source is never touched; a plain destination makes a renamed copy, a folder destination drops the copy inside under its original name, and copying a folder requires -r so its contents come along.
Section 5.2

5.2 mv - move or rename

mv has the same shape but moves instead of copying. The source disappears from its old location.

$ mkdir -p archive
$ cp cohort_2026.csv old_cohort.csv
$ mv old_cohort.csv archive/old_cohort.csv
$ ls archive
old_cohort.csv

There is no separate "rename" command - mv with a different destination name in the same folder is how you rename:

$ touch draft_cohort.csv
$ mv draft_cohort.csv final_cohort.csv

mv does NOT need -r for folders. A folder and its contents move together in one step.

Try it out

Try this snippet in the Bash Scratchpad on the right.

Try this snippet
$ touch report.txt
$ cp report.txt report_v2.txt
$ mv report.txt archive.txt
$ ls
mv simply rewrites a file's path, so pointing it at a new folder moves the file and pointing it at a new name renames it, all without -r and without ever leaving a copy behind.
mv simply rewrites a file's path, so pointing it at a new folder moves the file and pointing it at a new name renames it, all without -r and without ever leaving a copy behind.
Debug & fix

The code below has a bug, and it is already in the editor. Fix it there, then click Run & check. It passes when your code prints the expected output shown below (extra spaces and blank lines do not matter). Use Show hint only if you get stuck.

Broken code (as given)
# Copy patients.csv to a new file named my patients.csv, then list the new file
cp patients.csv my patients.csv
ls "my patients.csv"
Expected output
'my patients.csv'
Section 6

6 Removing - rm and rmdir

Deletion at the terminal is permanent. There is no Recycle Bin, no Trash, no Undo. Once a file is gone with rm, it is gone. Read that twice.

Section 6.1

6.1 rm - remove files

$ touch draft_cohort.csv
$ rm draft_cohort.csv
$ ls
(draft_cohort.csv is no longer listed)

To remove a folder and everything in it, add -r:

$ mkdir -p old_study/raw
$ rm -r old_study

You will see rm -rf in online examples. The -f flag is "force" - it suppresses every prompt and ignores every warning. Avoid -f as a beginner. If you mistype the path, it silently obliterates whatever you mistyped.

Adding -r to rm widens its reach from a single file to an entire folder, while -f removes the warnings that would let you catch a mistake, so rm -rf can wipe a whole directory silently and permanently.
Adding -r to rm widens its reach from a single file to an entire folder, while -f removes the warnings that would let you catch a mistake, so rm -rf can wipe a whole directory silently and permanently.

Until your fingers are calm, get into the habit of rm -i. Bash will ask you to confirm each file:

$ touch old_notes.txt
$ rm -i old_notes.txt
rm: remove regular empty file 'old_notes.txt'? y
Section 6.2

6.2 rmdir - remove an EMPTY folder

rmdir only removes folders that are completely empty. It is a safety net - if a folder still has anything in it, rmdir refuses, giving you a chance to notice.

$ mkdir scratch
$ touch scratch/things_i_forgot_about.txt
$ rmdir scratch
rmdir: failed to remove 'scratch': Directory not empty
$ ls scratch
things_i_forgot_about.txt
Try it out

Try this snippet in the Bash Scratchpad on the right.

Try this snippet
$ cp cohort_2026.csv scratch.csv
$ ls
$ rm scratch.csv
$ mkdir tmp_dir
$ rmdir tmp_dir
$ ls
Parsons problem · Copy first, then rename

All the lines you need are in the Line bank on the left — some may be distractors you should leave behind. Drag the lines you need into the Your solution column on the right, in the correct order, then click Check.

Task: You are about to clean up a copy of patients.csv. Make a working copy called working.csv. Keep a spare copy of it called spare.csv. Then rename the working copy to cleaned.csv. List spare.csv and cleaned.csv to show that both exist. Last, delete both with rm -v, which prints a line for each file it removes.

Line bank
  • mv cleaned.csv working.csv
  • cp patients.csv working.csv
  • rm -v spare.csv cleaned.csv
  • cp working.csv spare.csv
  • mv working.csv cleaned.csv
  • rm working.csv
  • ls spare.csv cleaned.csv
Your solution
  • Drop lines here, in order.
Section 7

7 Check your understanding

You have reached the end of the module. Try the same questions again — your answers here, paired with your pre-test answers, are how we measure what the module taught you. Answer every question and confidence rating, then click Submit and see results to view your score.

Post-test

Which command creates a new, empty file called patient_001.txt?

Post-test

You want to create the folder study/raw/vitals in one step, even though study/ does not exist yet. Which command works?

Post-test

What is the difference between cp and mv?

Post-test

Which command renames the file draft.csv to cohort_2026.csv?

Post-test

After running rm important.csv, how do you get the file back?

Post-test

Which command removes an EMPTY directory?

Post-test

What does the -i flag add to commands like rm, cp, and mv?

Post-test

You want to copy a folder and everything inside it. Which command works?

Post-confidence

I can create folders and empty files from the terminal.

Not at all confident
Fully confident
Post-confidence

I can copy and move files, and I know which command keeps the original.

Not at all confident
Fully confident
Post-confidence

I know why rm should be used carefully and what -i does.

Not at all confident
Fully confident
Section 8

8 Your results

Here is how your post-test answers compare with your pre-test answers. The pre/post pairing is the most reliable way to see what this module actually taught you.

Your score

Submit the post-test to see your results.

Muddiest point

What is the one thing from this module that is still unclear to you?

Rate this module

Overall, how would you rate this module?

How likely are you to recommend this module to a peer? (0 = not at all, 10 = extremely likely)