I have a list of directories
/home
/dir1
/dir2
...
/dir100
Some of them have no files in it. How can I use Unix find
to do it?
I tried
find . -name "*" -type d -size 0
Doesn't seem to work.
To determine how many files there are in the current directory, put in ls -1 | wc -l. This uses wc to do a count of the number of lines (-l) in the output of ls -1.
Finding Non-Empty Files Only Under the Given Directory As we've learned, find will search recursively under the given directory by default. If we want the find command only to scan the given directory, we can pass the -maxdepth 1 option.
Empty dirs in current dir: find . -type d -empty . In addition, empty files: find . -type f -empty in current dir and deeper.
-type f : Search and list files only. -type d : Find and list empty directories only. -empty : Only list empty files or folders on Linux or Unix. -ls : Show current file in ls -dils format on your screen.
Does your find have predicate -empty
?
You should be able to use find . -type d -empty
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With