There are multiple ways in which you can remove or delete a directory in Linux or macOS using terminal commands, lets see 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 see an example,
% 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 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 which 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, you command was successfully executed and the dir should be deleted.

More Posts related to Linux,
- Terminal display next month Calendar
- How to change bash terminal prompt string and color
- How to exit from nano command
- How to Display content of a file in Terminal Screen?
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- 3 Commands to stop Nginx Server
- How to check file permissions for your file using Linux/Unix/macOS Terminal Command
- Create Hidden File or Directory using Shell Command
- bash: cls: command not found
- How to install python pip on Ubuntu using apt command
- The Date Command and its usage [Linux - Unix - macOS]
- SCP Copy all files from directory to Local Folder
- Create and write file in single Linux/macOS command
- Install OpenSSL on Linux/Ubuntu
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- Check SSH/OpenSSH version Command
- Execute .bin and .run file Ubuntu Linux
- What does apt-get update command does?
- How to ls command to output one entry per line [macOS/Linux/Bash]
- 3 ways to clear screen on Linux Terminal
- How to backup a file in Linux/Unix
- How to quit or exit SFTP Prompt on Terminal
- How to use SCP Command to Copy Directory
- zsh hello world example
- How to remove/delete a directory in Linux/macOs
More Posts:
- [Hibernate] The method buildSessionFactory() from the type Configuration is deprecated - Java
- Save webpage as pdf in Google Chrome for Mac OS X - Mac-OS-X
- Fibonacci series from 1 to 500 table - Html
- The authenticated user is not authorized to access this resource - Stream/SharePoint/Teams/OneNote - Microsoft
- Android Studio: Cannot perform refactoring operation - Android-Studio