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.
Which command creates a new, empty file called patient_001.txt?
You want to create the folder study/raw/vitals in one step, even though study/ does not exist yet. Which command works?
What is the difference between cp and mv?
Which command renames the file draft.csv to cohort_2026.csv?
After running rm important.csv, how do you get the file back?
Which command removes an EMPTY directory?
What does the -i flag add to commands like rm, cp, and mv?
You want to copy a folder and everything inside it. Which command works?
I can create folders and empty files from the terminal.
I can copy and move files, and I know which command keeps the original.
I know why rm should be used carefully and what -i does.
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.
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 vitalsList several folders in one command to create them all:
$ mkdir raw_vitals cleaned_vitals lab_reports figuresTo 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
vitalsTry this snippet in the Bash Scratchpad on the right.
$ mkdir test_folder
$ ls
$ mkdir -p study/raw/vitals
$ ls study/raw

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
The 0 in the size column confirms the file is empty. You can pass several filenames at once.
Try this snippet in the Bash Scratchpad on the right.
$ touch a.txt b.txt c.txt
$ ls -lh
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.
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 vitalsIf 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.csvTo 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
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.csvThere 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.csvmv does NOT need -r for folders. A folder and its contents move together in one step.
Try this snippet in the Bash Scratchpad on the right.
$ touch report.txt
$ cp report.txt report_v2.txt
$ mv report.txt archive.txt
$ ls

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.
# 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"
'my patients.csv'
- Quote the new name: cp patients.csv "my patients.csv" ★
- Add -r: cp -r patients.csv my patients.csv
- Move the quotes: cp "patients.csv my" patients.csv
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.
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_studyYou 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.

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'? y6.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.txtTry this snippet in the Bash Scratchpad on the right.
$ cp cohort_2026.csv scratch.csv
$ ls
$ rm scratch.csv
$ mkdir tmp_dir
$ rmdir tmp_dir
$ ls
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.
mv cleaned.csv working.csvcp patients.csv working.csvrm -v spare.csv cleaned.csvcp working.csv spare.csvmv working.csv cleaned.csvrm working.csvls spare.csv cleaned.csv
- Drop lines here, in order.
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.
Which command creates a new, empty file called patient_001.txt?
You want to create the folder study/raw/vitals in one step, even though study/ does not exist yet. Which command works?
What is the difference between cp and mv?
Which command renames the file draft.csv to cohort_2026.csv?
After running rm important.csv, how do you get the file back?
Which command removes an EMPTY directory?
What does the -i flag add to commands like rm, cp, and mv?
You want to copy a folder and everything inside it. Which command works?
I can create folders and empty files from the terminal.
I can copy and move files, and I know which command keeps the original.
I know why rm should be used carefully and what -i does.
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.
Submit the post-test to see your results.
What is the one thing from this module that is still unclear to you?