Ever wondered how you can delete all the empty directories in Linux?
I bet you did, there are many ways to achieve that in GNU/Linux, however here is one way you might go:
First it is probably a good idea to list the empty directories and examinethe empty directories before you take the next step and execute a command to delete them:
find . -depth -type d -empty
Now after you take a close look in the directories, next step to partake is delete the directories.
find . -depth -type d empty -exec rmdir {} ;
Be aware that in the above examples, the first one would list all directories in your current directory in which you
execute the command, the second example will delete all the empty directories starting from your current directory unto thedeepest located empty directory in the directory tree.
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
Hey long time now see, thanks for dropping back again! 🙂
More helpful Articles
- Delete empty files and directories under directory tree in Linux / UNIX / BSD
- Howto delete multiple files in Linux and FreeBSD / How to deal with “Argument list too long” error while deleting many files in directory
- * How to stop unattended upgrades on Debian / Ubuntu and other deb based Linux
- How to configure Joystick ( Gamepad ) on Debian, Ubuntu, Mint GNU / Linux easily
- Install TeamViewer on latest Debian, Ubuntu, Fedora, CentOS Linux quick how to
- How to check Linux OS install date / How long ago was Linux installed
- Find all hidden files in Linux, Delete, Copy, Move all hidden files
- KVM Creating LIVE and offline VM snapshot backup of Virtual Machines. Restore KVM VM from backup. Delete old KVM backups
- Generate and Add UUID for every existing Redhat / CentOS / RHEL network interface to configuration if missing howto
- Install Zabbix Proxy configure and connect to Zabbix server on CentOS Linux
- Switching from PasswordSafe to Keepass database, migrating .psafe3 to .kdbx format howto
- Enable zabbix agent to work with SeLinux enabled on CentOS 7 Linux
- How to extend LVM full partition to bigger size on Linux Virtual machine Guest running in VMware vSphere
- Install Zabbix Agent client on CentOS 9 Stream Linux, Disable Selinux and Firewalld on CentOS9 to make zabbix-agentd send data to server
Download PDF Tags: Delete, directories, empty, howto, Linux
This entry was posted on Wednesday, April 7th, 2010 at 6:47 pm and is filed under System Administration. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.18 Safari/534.10
You’ll want to quote the “{}” if the directly names can contain spaces.
View CommentView CommentMozilla/5.0 (X11; U; Linux x86_64; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/531.2+ Debian/squeeze (2.30.6-1) Epiphany/2.30.6
thx for the tip Adam
View CommentView Comment