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!
- [Fix] Linux - bash: useradd: command not found
- Calculate days between dates using dateutils ddiff command
- pwd Command - Print Working Directory
- Rename a directory using Linux/Unix command
- How to go to the End of File in Nano Editor
- How to tar.gz a directory or folder Command
- How to remove/delete a directory in Linux/macOs
- How to Display content of a file in Terminal Screen?
- ls command sort by file size [Linix/UNIX/macOS/bash]
- How to Copy Entire Directory to another Directory in Linux
- 3 ways to clear screen on Linux Terminal
- Command to check Last Login or Reboot History of Users and TTYs
- How to check uptime of Linux/Unix/macOS system/server using console command?
- How to backup a file in Linux/Unix
- Command to know the installed Debian version?
- Check SSH/OpenSSH version Command
- 3 Commands to stop Nginx Server
- Linux: Create a New User and Password and Login Example
- How to install npm on Ubuntu
- How to List All Users in Linux
- How to Get the List of Shells on Linux
- Fix - ssh-copy-id no identities found error
- Installing and using unzip Command to unzip a zip file using Terminal
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- zsh hello world example
- Android : Exception raised during rendering: action_bar API 22 - Android
- Create and write file in single Linux/macOS command - Linux
- Audio Video Network protocols supported by Android OS Devices - Android
- INSTALL_FAILED_INSUFFICIENT_STORAGE Error Android Emulator - Android
- Microsoft Teams enable or disable Spell check - Teams
- Reopen previously closed tab in Google Chrome - Chrome
- How to enable, create and use Virtual Breakout Rooms in Microsoft Teams - Teams