files
rm
Removes files and, with -r, directory trees. Deletions are immediate and not recoverable from the shell.
rm [OPTION]... FILE... Common flags
| Flag | Purpose |
|---|---|
| -r | Recursively remove directories and their contents |
| -f | Force: ignore nonexistent files, never prompt |
| -i | Prompt before each removal |
| -v | Verbose: print each file removed |
| -d | Remove empty directories |
| --one-file-system | Skip mount points when recursing (safety on -rf) |
Examples
rm notes.txt Delete a single file
rm -rf build/ Delete an entire build directory tree
rm -i *.bak Interactively clean up backup files
rm -v -- -oddname.txt Delete a file whose name starts with a dash using --
Gotcha
rm -rf / (or an unexpanded variable in a path like rm -rf $VAR/) can nuke a system; always quote paths and consider --one-file-system.
Related commands
mv
Moves or renames files and directories. Within a filesystem it just relinks; across filesystems it copies then deletes.
find
Recursively walks directories evaluating expressions on each entry. Combines discovery with actions like exec or delete.
chmod
Changes file mode (permission bits). Accepts symbolic modes like u+x or octal modes like 755.
ls
Lists directory contents including files and subdirectories. Supports detailed views, sorting, and filtering to inspect the filesystem quickly.
cp
Copies files and directories from one location to another. Preserves or transforms metadata depending on flags.