If you are on Ubuntu and feel brave or foolish enough to delete a folder from the command line you are in the right place. This guide covers the rm command and safer alternatives so you can remove a directory on Linux without triggering a small catastrophe.
First rule of terminal club do not guess. Verify your working directory and the folder contents before you type anything that looks permanent. A quick check will save you from That Awful Moment.
pwd
ls -la /path/to/folder
If you want to see everything recursively run
ls -R foldername
The classic tool is the rm command. Use rm -r to remove a directory and its contents recursively. It will delete files and nested directories so pause for dramatic effect before pressing enter.
rm -r foldername
If you add -f you force removal and skip prompts. This is useful when scripting but dangerous when you are awake and supposed to be attentive.
rm -rf foldername
For a cautious approach try interactive mode which asks before deleting each file
rm -ri foldername
Sometimes the system protects files from your mortal user. sudo lets you act as root so you can remove stubborn directories. Double check the path because root does not care about regrets.
sudo rm -r foldername
If you like the comfort of a safety net install trash-cli and send items to the trash instead of nuking them. This works on Ubuntu and most Linux setups and gives you a chance to recover a mistake.
sudo apt update && sudo apt install trash-cli
trash-put foldername
To restore use the appropriate trash-cli command or open your desktop trash if you have one. This is the adult way to delete things from the terminal.
If the folder is valuable make a quick copy before removing it. A backup is a small act of humility that can save your job or your pride.
cp -r foldername foldername_backup
There you go a compact and practical approach to delete folder tasks on Ubuntu from the terminal. Follow these steps to remove directory trees safely and keep the drama to a minimum. If you still feel nervous take a deep breath and open a backup before proceeding.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.