How to Remove Directory in Bash Terminal
Fumbani Banda
Feb 15, 2024
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
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
Author: Fumbani Banda