Friday, June 12, 2015

linux - List all empty folders



I have a bunch of nested folders. Most folders contain files. Some contain hundreds of thousands of files. Some are empty.




I want to get a list of all empty folders. However, when I run:



find -type d -empty


it takes a very long time to run, a lot longer than it takes to run just find -type d. I suspect that -empty is checking all files to see if they are empty, then -type d is skipping the files.



So is there:



1) a way to optimize find so that it will a) find all folders, then b) list the empty ones?




or



2) a different command (or commands) that I could use to get this list?


Answer



Try this



find / -xdev -type d -exec find {}  -maxdepth 0 -empty  \;



or the marginally faster



find / -xdev -type d | xargs -I{} find {} -maxdepth 0 -empty

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...