Mohamed Sharaf

Delete a whole directory over SSH

The one-line command to remove a folder and everything inside it on Linux, and the care it deserves.

· 1 min read

From the archive: first published on mohamedsharaf.net in March 2011. Rewritten and checked in 2026; some details may be out of date.

To delete a folder with all its files and subfolders on a Linux server:

rm -rf /path/to/folder
  • -r removes the folder recursively, with everything inside it.
  • -f forces it, without asking for confirmation.

That last part is exactly why it needs respect. There is no recycle bin and no “are you sure?”. Before pressing Enter, run ls /path/to/folder to see what you are about to delete, avoid wildcards you have not checked, and never run it with a path built from a variable that might be empty.

ShareWhatsAppLinkedInXTelegramFacebook