In order to delete a directory (dir) on your Mac running macOS via the Terminal application you can make use of the rmdir command
Syntax:rmdir path-of-the-directory - if the dir is empty
rm -r path-of-the-directory
Example:
Let's first create a directory in the Desktop and name it myDir, lets add few files to it, I use the touch command just to create blank files abc.txt, xzy.csv so that the directory is not empty.
% mkdir myDir
% cd myDir
% touch abc.txt
% touch xyz.csv
% cd ..
% rmdir myDir
rmdir: myDir: Directory not empty
As you can see the myDir directory is not deleted as it is not empty, in order to delete the directory with files and folders in it you can make use of rm command with -r parameter.
Example:code2care@mac Desktop % rm -r myDir

remove dir on mac using rm command
Troubleshooting steps:
Note if the directory does not exist and you use the rmdir command you will get a "No such file or directory" error
code2care@mac Desktop % rmdir mydir1
rmdir: mydir1: No such file or directory

No such file or directory
If the object you are trying to delete and it's not a directory - i.e. a file you will get an error like - Not a directory
code2care@mac Desktop % rmdir myfile.txt
rmdir: myfile.txt: Not a directory
Options that you can use with rm command
- -r :Recursive: remove directories and their contents recursively
- -f :Force: ignore nonexistent files, never prompt
- -i :Interactive: prompt before every removal
- -l :Interactive: only prompt before removing more than three files
- -r :Verbose: explain what is being done

Directory is not empty
Have Questions? Post them here!
More Posts related to MacOS,
- How to connect AirPods to Mac
- Display Safari URL address link on hover
- Mac turn dark mode on or off using terminal command
- Docker Desktop needs privileged access macOS
- How to install Java on macOS [Big Sur]
- How to start/boot macOS in safe mode - Big Sur 11.0, Catalina 10.15, or Mojave 10.14
- Find Mac version using terminal command
- How to fix command not found brew (bash, zsh) on macOS Terminal
- How to change default macOS Terminal Window size
- How to make EditText text to uppercase or lowercase on macOS
- Disable Startup Sound on macOS
- How to switch from bash to zsh shell in macOS Terminal
- How to make macOS Terminal window Transparent (or Opaque)
- Remove Now Playing icon from macOS Big Sur Menu Bar
- Test internet speed using macOS Terminal command
- How to change macOS Safari default language
- Encode or Decode Base64 String using Mac Terminal Command
- Safari - Get HTTP Request Response Headers
- How to open terminal on Mac to run commands
- How to install homebrew (brew) on M1 Mac
- How to display directory tree in Mac Terminal
- How to Change Mouse Wheel Scroll Direction on Mac
- MacoOS - xyz is an app downloaded from the internet. Are you sure you want to open it? Alert
- The default interactive shell is now zsh. [macOS]
- Change Terminal Cursor Type in Mac (MacOS Shell)
More Posts:
- What is CA FE BA BE 00 00 00 3D in Java Class Bytecode - Java
- Common Microsoft Teams sign in errors and how to fix - Teams
- Portable Notepad++ for windows - NotepadPlusPlus
- Twitch chat down, error loading data, content unavailable, streaming problem - News
- How to check if a port is in use using terminal [Linux or macOS] - MacOS
- How to enable Do Not Disturb mode for Notification Center in Mac OS X 10.10 Yosemite - Mac-OS-X
- Using Java 8 Month Enum with Examples - Java
- Change Android Toast background color - Android