Delete folder in Ubuntu example How to remove a directory |Video upload date:  · Duration: PT1M17S  · Language: EN

Learn how to remove a directory recursively in Ubuntu using rm and safer methods including sudo and trash cli for safer deletion in the terminal

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.

Confirm the target directory

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

Run the recursive remove command

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

Use sudo when permissions block you

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

Safer trash approach with trash-cli

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.

Quick backup option

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

Final checklist to avoid panic

  • Confirm path with pwd and ls -la
  • Preview contents with ls -R foldername
  • Consider cp -r for a local backup
  • Use rm -ri for interactive deletion if you want prompts
  • Use trash-put from trash-cli when you want a safety net
  • Only use sudo when you understand why you need it

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.