READDEMOGUIDED LABINDEPENDENT LABQUIZREVIEW
Module 2 of 7 · 25 min

Working with files and directories

Beginner · 1/5

Written by CoreQ Academy (drafted with AI assistance). Awaiting review by Sean Ofodile.

You will be able to
  • Create, copy, move and remove files and directories
  • Write output to files with > and >>
  • Avoid destructive mistakes with rm

Creating things

mkdir creates directories (-p creates parents too). touch creates an empty file or updates a timestamp.

$ mkdir -p projects/2026/q4
$ touch projects/2026/q4/plan.txt

Copying and moving

cp SRC DEST copies; add -r for directories. mv moves or renames. If the destination is an existing directory, the file goes inside it.

Redirection

> sends a command's output to a file, replacing it. >> appends. 2> captures error messages.

$ echo "first" > log.txt
$ echo "second" >> log.txt
$ cat log.txt
first
second

Removing safely

rm deletes immediately; there is no recycle bin. rm -r deletes directories and everything inside. Run ls on the same path first so you see exactly what you are about to remove.

Demo: try these in the terminal

mkdir -p projects/democreate nested folders
echo "hello" > projects/demo/hi.txtwrite a file
cp projects/demo/hi.txt hi-copy.txtcopy it
mv hi-copy.txt projects/move it into a directory
rm projects/hi-copy.txtremove it

Quiz

Knowledge quiz · pass mark 80%
  1. notes/ is a directory. What does mv todo.txt notes do?
  2. Which option lets cp copy a directory and its contents?
  3. What does >> do?
  4. Write the text done into status.txt, replacing whatever is there.
    $
  5. Put these steps for safely deleting old logs in order.
    1. confirm these are the files you want gone
    2. ls to verify
    3. rm -r old-logs/
    4. ls old-logs/
  6. Create the directory a/b/c in one command, including missing parents.
    $
  7. Files removed with rm go to a trash folder by default.
  8. Which redirect captures only error messages?