Sling Academy
Home/DevOps/Ubuntu: How to Delete a Folder and Its Contents

Ubuntu: How to Delete a Folder and Its Contents

Last updated: December 03, 2023

In order to delete a folder and all of its contents (subfolders and files) in Ubuntu, you can use the rm command with some options. The rm command stands for remove and it is used to delete files and directories in Linux. Here are the steps to follow:

1. Navigate to the parent directory of the folder you want to delete using the cd command. For example, if you want to delete a folder named test in your home directory, you can type:

cd ~

2. Use the rm command with the -r and -f options to delete the folder and its contents recursively and forcefully. The -r option means recursive, so it will delete the folder and all its subfolders and files. The -f option means force, so it will not ask for confirmation before deleting. For instance, you can run the following command to delete the folder named test:

rm -r -f test

3. Verify that the folder and its contents are deleted by using the ls command to list the files and directories in the current directory.

In conclusion, you can use the rm command with the -r and -f options to delete a folder (including its subfolders and files) in Ubuntu. Be careful when using this command, as it will permanently remove the files and directories without any recovery option. 

Next Article: Homebrew: How to Start/Stop/Restart a Service

Previous Article: How to install/upgrade/remove Homebrew on Mac OS

Series: Linux Tutorials

DevOps

You May Also Like

  • How to reset Ubuntu to factory settings (4 approaches)
  • Making GET requests with cURL: A practical guide (with examples)
  • Git: What is .DS_Store and should you ignore it?
  • NGINX underscores_in_headers: Explained with examples
  • How to use Jenkins CI with private GitHub repositories
  • Terraform: Understanding State and State Files (with Examples)
  • SHA1, SHA256, and SHA512 in Terraform: A Practical Guide
  • CSRF Protection in Jenkins: An In-depth Guide (with examples)
  • Terraform: How to Merge 2 Maps
  • Terraform: How to extract filename/extension from a path
  • JSON encoding/decoding in Terraform: Explained with examples
  • Sorting Lists in Terraform: A Practical Guide
  • Terraform: How to trigger a Lambda function on resource creation
  • How to use Terraform templates
  • Understanding terraform_remote_state data source: Explained with examples
  • Jenkins Authorization: A Practical Guide (with examples)
  • Solving Jenkins Pipeline NotSerializableException: groovy.json.internal.LazyMap
  • Understanding Artifacts in Jenkins: A Practical Guide (with examples)
  • Using Jenkins with AWS EC2 and S3: A Practical Guide