There are multiple ways in which you can remove or delete a directory in Linux or macOS using Terminal commands, let us take a look at some of them,
Remove directory using rmdir command
rmdir is a command line utility that you can use to delete empty directories, this will work only when the directory is empty, let's see some examples,
% mkdir myDir
% rmdir myDir
%
In the below example we created a directory and add a file in it, now if you try to delete the directory you will get the error "Directory not empty"
% mkdir myDir
% cd myDir
% touch myFile.txt
% cd ..
% rmdir myDir
rmdir: myDir: Directory not empty
%
Remove directory using rm command
If you want to remove a directory that contains directories and files in it you can make use of rm -r command,
% rm myDir
rm: myDir: is a directory
% rm -r myDir
%
If you get no error and you are returned to the prompt returns, your command was successfully executed and the dir should be deleted.

Have Questions? Post them here!
- How to Display content of a file in Terminal Screen?
- How to Install CVS Version Control on Linux/Ubuntu
- How to install and Configure sar sysstat tools in Ubuntu Linux
- ls command to list only directories
- [Ubuntu] Search a package and versions using apt command
- zsh hello world example
- Linux Remove or Delete Files and Directories using Terminal Commands
- How to tar.gz a directory or folder Command
- Calculate days between dates using dateutils ddiff command
- How to ls command to output one entry per line [macOS/Linux/Bash]
- 3 Commands to stop Nginx Server
- Create and write file in single Linux/macOS command
- SCP Copy all files from directory to Local Folder
- How to go to the End of File in Nano Editor
- How to remove/delete a directory in Linux/macOs
- How to Copy Entire Directory to another Directory in Linux
- Execute .bin and .run file Ubuntu Linux
- The Date Command and its usage [Linux - Unix - macOS]
- Fix - ssh-copy-id no identities found error
- How to check uptime of Linux/Unix/macOS system/server using console command?
- How to Select All text in vim/vi editor using Keyboard
- Linux: Create a New User and Password and Login Example
- Command to display epoch time Terminal
- How to install curl on Alpine Linux
- How to exit from nano command
- SharePoint CAML query error - The XML source is not correct - SharePoint
- Detect swipes on Android Activity - Android
- Android RatingBar Example - Android
- Disable Apps from Opening on Mac Startup (Login items) - MacOS
- Cant find System Preferences... under macOS Ventura Apple Menu? - MacOS
- How to upgrade Docker Desktop on Mac - MacOS
- How to migrate Kaizala to Microsoft Teams - Teams
- Generate Project Dependency tree using Gradle Command - Gradle