rm (GNU) Cheatsheet #
The rm
command is used to remove files or directories in Unix-like operating systems.
Basic Commands #
Command/Option | Example | Description |
---|---|---|
rm file | rm example.txt | Remove a file |
rm -r dir | rm -r mydir | Remove a directory and its contents |
rm -f file | rm -f example.txt | Force remove a file, ignore nonexistent files |
rm -i file | rm -i example.txt | Prompt before every removal |
rm -r -i dir | rm -r -i mydir | Prompt before removing each file in a directory |
Advanced Options #
Command/Option | Example | Description |
---|---|---|
rm -d dir | rm -d emptydir | Remove an empty directory |
rm -v file | rm -v example.txt | Verbose mode, show files as they are removed |
rm --one-file-system | rm --one-file-system -r mydir | Remove directory and its contents, only within the same file system |
rm --no-preserve-root | rm --no-preserve-root -r / | Ignore the safety check for removing / |
This cheatsheet covers essential GNU rm
options for file and directory removal.