Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Shell script to delete empty folders recursively     - Ubuntu Linux installation GAMIT10.6 (Linux)

- Using iptables achieve NAT (Linux)

- Mac OS X 10.9 compiler OCI8 module (Programming)

- Shilpa Nair interview experience sharing RedHat Linux package management (Linux)

- CentOS 6/7 Series Docker Installation (Linux)

- Compile and install Ubuntu Linux 4.0.5 kernel, network and fix vmware kernel module compilation error (Linux)

- C ++ type conversion and RTTI (Programming)

- Linux installed and tested the deployment of Kafka distributed cluster (Server)

- Profile Linux users login shell and login to read (Linux)

- NAT and firewall under Linux (Linux)

- MySQL 5.6 master-slave replication configuration (Database)

- linux smartd [FAILED] appears at startup (Linux)

- Java proxy use and proxy principle (Programming)

- Oracle TDE transparent data encryption (Database)

- Oracle table space is too large processing time (Database)

- CentOS7 install MySQL 5.5 (Database)

- JavaScript file loader LABjs API Explanation (Programming)

- To install the Git and Github under Ubuntu (Linux)

- Python Flask environment to build (Linux)

- Help you to see Linux system architecture type 5 Common Commands (Linux)

 
         
  Shell script to delete empty folders recursively
     
  Add Date : 2017-08-31      
         
         
         
  Sometimes we need to recursively delete empty folders, Internet looking for a bit, did not find a better Shell script, so write himself a script.

#! / Bin / bash
# Des: delete empty directories recursive
deleteempty () {
     find $ {1: -.} -mindepth 1 -maxdepth 1 -type d | while read -r dir
     do
         if [[-z "$ (find" $ dir "-mindepth 1 -type f)"]]> / dev / null
         then
             echo "$ dir"
             rm -rf $ {dir} 2> & - && echo "! Empty, Deleted" || echo "Delete error"
         fi
         if [-d $ {dir}]
         then
             deleteempty "$ dir"
         fi
     done
}

deleteempty
The contents of the script is very simple directory traversal to find an empty folder, and then delete it.

use

If the file structure of the script file dedr.sh, we tested

Run the script:

# Sh dedr.sh

Deleted files:

result:

We can see the empty folder has been deleted.
     
         
         
         
  More:      
 
- Easy to install CentOS 6.6 desktop environment (Linux)
- Raspberry Pi configuration wireless hotspot (Linux)
- Talk Packages (Linux)
- By way of a binary installation innobackupex (Database)
- Linux package management operations Basic entry (Linux)
- RedHat Linux 5.5 installation process SVN Service Notes (Server)
- Define and modify strings principle in Python (Programming)
- Disk Management LVM (Linux)
- MySQL migration tool used in the production environment (Database)
- HBase Application Development Review and Summary of Series (Database)
- Java collections series (Programming)
- Ubuntu 15.04 using the Eclipse 4.4, Java 8 and WTP (Linux)
- Common DDOS attacks (Linux)
- Linux RAID Set RAID 10 or 0 + 1 (Linux)
- HTTPS and SSH and use the difference between the way: Git User's Manual (Linux)
- Httpclient4.4 of principle (Http execution context) (Programming)
- Ubuntu disable graphics card (Linux)
- Kali Linux resolve GPG error KEYEXPIRED 1425567400 (Linux)
- Getting Started with Linux: Learn how to install and access CentOS 7 Remote Desktop on a VPS (Server)
- Linux POST fstab configuration file read-only variable can not be modified problem (Linux)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.