I would like to find (later delete) all music folders that are nearly empty (Banshee deletes only the music files but not the other files in there).
I tried with:
find -type d -size -500k \;
But it shows folders that contain bigger files too.
find -type d -size -500k -exec du {} \;
shows the correct size.
How to modify the find cmd to only show folders that are smaller then N?
One command I use, as long as you don't need to pipe this straight into another script, is
du . | sort -rn
This would put the smallest folders at the bottom of the printed list along with their sizes. It would take a bit more work to filter out the ones that are larger.
If you simply want to delete folders which contain under N bytes, the following one liner will work:
What does this do? Consecutively:
du
prints sizes of directories along with their paths$1 <= 500
is a condition that tests if the first column is under 500 (if it's smaller than 500 bytes)print
in awk printsrm -rf "/path/to/small/dir"
| sh
pipes it into sh so it can be executedYou could also do it using xargs instead of piping it into sh, but I'm used to this way.