What does rm -rf do, and how do you avoid deleting the wrong thing?
rm -rf removes files and directories recursively and without prompting, and there is no recycle bin. Avoid accidents by checking with ls first, quoting variables, never running it as root casually, and using rm -i or trash tools where possible.
Explain it simply
Linux has no recycle bin on the command line. rm removes the directory entry and the data is effectively gone. -r means recursive (go into folders) and -f means force (ignore missing files, never ask).
The famous disasters come from empty variables or stray spaces. If $DIR is empty, rm -rf $DIR/* becomes rm -rf /*. A space in rm -rf /home/amit /old deletes two paths.
Habits that protect you: run ls with the exact same path first, quote variables as "$DIR", use ${DIR:?} so the shell aborts if the variable is empty, and prefer rm -ri for anything unfamiliar. GNU rm also refuses rm -rf / by default because of --preserve-root.
Example
DIR=""
rm -rf "${DIR:?DIR is not set}"/*
# bash: DIR: DIR is not set (nothing is deleted)
ls build/ && rm -rf build/What to say in the interview
"rm -rf deletes recursively with no confirmation and no undo. I preview the target with ls, quote variables, use ${VAR:?} to guard against empty values, and avoid wildcards as root. For important data I make sure a backup exists first."
Common mistakes
- Running rm -rf with an unquoted variable that could be empty.
- Assuming deleted files can be recovered easily.