How do I delete / remove a directory under UNIX operating systems?
You need to use rmdir command to remove a directory. It will remove the directory entry specified by each dirname operand, which must refer to an empty directory.
For example, to remove a directory called “cppcode”, enter:
rmdir cppcode
Note: A directory must be empty before it can be removed. Use rm command to remove all files from a directory:
cd cppcode
rm *.cpp
cd ..
rmdir cppcode
You can also recursively remove directories and subdirectories. The directory will be emptied of files and removed using rm command:
rm -r oldletters
🐧 20 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Hi thanks..
Thank You
thank u.I want more basic comends in unix
What are the other conditions for deleting/removing directories…….?
Thanks
learning unix begins with deleting directories.
Nice
The commands are well explained with proper example. Very helpful!!
Thanks.
Fantastic! Thank you!
Thanks !!
Thanks. It works.
if you do rm -fr cppcode, it will forcefully delete the directory(making it empty and delete).
Thanks,
KARAN
It helped me :) thanks a tone :))))))
You could also do a:
rm -rf
thaks bt i want more
Thanks it works
thanks a lot..it solved my problem in a beautiful way
rm -fr also removed forcefully.
Is there any way to delete directory recurisively,,without deleting content of each directory .