How to Remove Directory in Bash Terminal

  1. Check Directory Content in Bash
  2. Remove Directory in Bash
How to Remove Directory in Bash Terminal

This tutorial demonstrates removing a directory with subdirectories in the bash terminal.

Check Directory Content in Bash

Here, we enter into the testfolder directory that we want to delete using cd. We display all the contents in the directory using ls -R * to have an idea of what we are going to delete.

cd testfolder
ls -R *

Output:

From the output, we have two subfolders inside the testfolder directory.

remove directory in bash terminal

Remove Directory in Bash

The following command removes everything inside the directory testfolder, including the testfolder directory itself. The -r option recursively removes the directories and their contents while -f stands for force, which says delete everything without asking.

Make sure you are outside of the directory that you want to remove before running the command below.

rm -rf testfolder
Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe
Fumbani Banda avatar Fumbani Banda avatar

Fumbani is a tech enthusiast. He enjoys writing on Linux and Python as well as contributing to open-source projects.

LinkedIn GitHub

Related Article - Bash Directory