Category: Advanced (Command Line) • Est. reading time: 3 minutes
Deleting files from the command line is fast, and that is exactly why it deserves respect. There is no trash bin and no undo. Once you remove something over SSH, it is gone. Here are the commands and, just as importantly, how to use them without regret.
Remove a File
rm filename.txt deletes a single file.
Remove an Empty Folder
rmdir foldername removes a folder, but only if it is already empty.
Remove a Folder and Everything in It
rm -r foldername deletes a folder along with all its contents. The r means recursive.
Read this before using rm -rf. Adding f (force) deletes without asking any questions, which is powerful and dangerous. Double-check the path every single time. A command like rm -rf pointed at the wrong directory can wipe out far more than you intended, with no way back. When in doubt, list the folder contents first, or make a tar backup before you delete.
Uneasy about running delete commands on your server? That caution is well placed. Let us handle it. Reach us at support@allydrez.com or 1-321-209-2004.