The previous lesson created, copied and moved files; this one covers the two operations that complete the picture. Deleting on the command line is permanent — there is no recycle bin — so you will learn the flags that keep rm safe. You will also learn to create links, which let one file appear in several places and are used everywhere from /usr/bin to your own project deployments.
rm removes files immediately. It does not ask for confirmation, and the space is reused as soon as no process holds the file open.
rm notes.txt # delete a file
rm a.txt b.txt c.txt # delete several
rm -i report.pdf # prompt before each deletion
rm -v *.tmp # verbose: print each name as it goesDirectories need the recursive flag, and non-empty directories need it too:
rm -r build/ # delete build and everything inside it
rm -rf build/ # -f: no prompts, no error if it does not existrm -rf is the most dangerous command you will use regularly. A stray space turns rm -rf ~/tmp into rm -rf ~ /tmp, which wipes your home directory. Rules that prevent disasters:
rm -rf with a variable you have not checked: rm -rf "$DIR"/ deletes / if DIR is empty. Write rm -rf "${DIR:?}/" so bash aborts when it is unset.rm -ri when cleaning up interactively; the prompt costs a second and saves a day.rm -- -draft.md or rm ./-draft.md.rmdir removes a directory only if it is empty, which makes it a safe alternative when you expect emptiness.
rmdir logs
# rmdir: failed to remove 'logs': Directory not empty
rmdir -p a/b/c # remove c, then b, then a if each becomes emptyOn Linux a file's data and metadata (permissions, owner, timestamps) live in an inode identified by a number. A filename is merely a directory entry pointing at an inode. ls -i shows the number. This model is what makes links possible: several names can point at one inode, and a name can point at another name.
A hard link is a second directory entry for the same inode. Both names are equal; neither is "the original". The data is deleted only when the last link is removed.
echo "v2 config" > config-v2.txt
ln config-v2.txt config-hard.txt
ls -li1310745 -rw-r--r-- 2 alice alice 10 Sep 27 10:00 config-hard.txt
1310745 -rw-r--r-- 2 alice alice 10 Sep 27 10:00 config-v2.txtBoth lines show the same inode (1310745) and a link count of 2. Editing through either name changes the shared content. Hard links cannot cross filesystems and cannot point at directories.
A symbolic (soft) link is a small file containing a path. It can point at a file or directory on any filesystem, and it is what most people mean by "a link".
ln -s config-v2.txt config.txt
ls -l config.txt
# lrwxrwxrwx 1 alice alice 13 Sep 27 10:01 config.txt -> config-v2.txt
ln -s /var/www/releases/2026-09-27 /var/www/current # link to a directory
ln -sfn /var/www/releases/2026-09-28 /var/www/current # atomically repoint itThe l at the start of the permissions and the -> arrow mark a symlink. If the target is deleted the link remains but is dangling; ls colours it red and reading it fails with "No such file or directory". Use readlink -f config.txt to resolve the final target. rm config.txt removes the link, not the file it points to.
| Feature | Hard link | Symbolic link |
|---|---|---|
| Points at | Inode | Path (by name) |
| Survives deleting the original | Yes | No (becomes dangling) |
| Can cross filesystems | No | Yes |
| Can link directories | No | Yes |
| Created with | ln target name | ln -s target name |
/usr/bin/python3 -> python3.12: versioned binaries with a stable name./etc/nginx/sites-enabled/app -> ../sites-available/app: enabling a config by linking it.current -> releases/<timestamp>: zero-downtime deploys switch a symlink instead of copying files./bin -> usr/bin: the merged directory layout on modern distributions.ln -s ../data/db.sqlite db is resolved relative to the link's location, not to where you ran the command. When in doubt use an absolute target.ln -s TARGET LINKNAME, the same order as cp SOURCE DEST.rm -r on a symlink to a directory with a trailing slash: rm -r link/ follows the link and deletes the contents. Use rm link without the slash.What is the safest way to delete a directory tree interactively?
rm deletes permanently; -r for directories, -i to confirm, -f to suppress prompts and errors.rm -rf "${DIR:?}/" and read the line before pressing Enter.rmdir only removes empty directories, which makes it safe.ln -s TARGET LINKNAME — the argument order matches cp.Next lesson: Viewing Files: cat, less, head, tail — read file contents, page through long output and follow logs as they grow.