Latticework

Command Palette

Search for a command to run...

Terminal / CLI

File Operations

12 min

Explanation

cp source dest copies a file (add -r to copy a directory and everything inside it); mv source dest renames or moves a file — there's no separate "rename" command, moving to a new name in the same directory IS a rename. rm deletes a file; deleting a directory requires rm -r explicitly, since removing a whole tree of files is destructive enough that the shell won't do it by accident. rm -f suppresses errors for files that don't exist, useful in scripts that shouldn't fail just because something was already cleaned up.

echo draft content > draft.txt
cp draft.txt backup.txt
mv draft.txt final.txt
rm backup.txt
ls
# final.txt
Try it

The first rm on a directory fails on purpose — it's a safety rail. rm -r is the explicit, harder-to-typo-into-by-accident way to confirm you really do want to delete the whole tree.

Loading editor…
Exercise

Create a file `draft.txt` containing the text `hello`, copy it to `draft-backup.txt`, rename `draft.txt` to `final.txt`, and finally delete `draft-backup.txt`.

Quiz

You run `rm important-dir` on a directory (not a file) without any flags. What happens?

Checkpoint

You can copy, move/rename, and delete files and directories, and you understand why deleting a directory needs an explicit flag.