READDEMOGUIDED LABINDEPENDENT LABQUIZREVIEW
Module 2 of 7 · 25 min Working with files and directories
Beginner · 1/5Written 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.txtCopying 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
secondRemoving 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/demo | create nested folders |
echo "hello" > projects/demo/hi.txt | write a file |
cp projects/demo/hi.txt hi-copy.txt | copy it |
mv hi-copy.txt projects/ | move it into a directory |
rm projects/hi-copy.txt | remove it |
Quiz
Knowledge quiz · pass mark 80%
- notes/ is a directory. What does mv todo.txt notes do?
- Which option lets cp copy a directory and its contents?
- What does >> do?
- Write the text done into status.txt, replacing whatever is there.$
- Put these steps for safely deleting old logs in order.
- confirm these are the files you want gone
- ls to verify
- rm -r old-logs/
- ls old-logs/
- Create the directory a/b/c in one command, including missing parents.$
- Files removed with rm go to a trash folder by default.
- Which redirect captures only error messages?