RFE: find <path> -d -size 0 => doesn't find empty directories

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

RFE: find <path> -d -size 0 => doesn't find empty directories

L A Walsh
Something I can use on my /tmp files on linux is a find command:

find /tmp -size 0 -delete

to delete zero-len-files or empty-directories in /tmp.

Unfortunately, due to directories really not being in the user
disk data space, but in the MFT(zone) (I think), the size
comes back as zero ('0') for directories.

Would it be possible (if not problematic) for the cygwin
emulation layer to return some non-zero value if the
directory has actual entries in it (ignoring structural
values like "." and "..")?  Maybe return as 'size' either
a dummy number proportional to #entries (like 10*#entries),
or something like summing up actual number (+1) of characters
in the file list?

Would that be difficult to do, or add?

Thanks much,
-linda



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: RFE: find <path> -d -size 0 => doesn't find empty directories

Norton Allen
On 10/31/2018 7:02 PM, L A Walsh wrote:
> Something I can use on my /tmp files on linux is a find command:
>
> find /tmp -size 0 -delete
>
> to delete zero-len-files or empty-directories in /tmp.

What flavor of Linux are you using where this works for you? I'm running
Ubuntu 16.04 at the moment, and I just tried the following in an
otherwise empty directory:

    $ mkdir b
    $ find . -size 0

The directory 'b' did not show up, hence was not reporting as size 0.
The man page for -size does not mention any special behavior for
directories as opposed to regular files, so I would expect Linux to
never report any directory as size 0, since they always have '.' and
'..' entries, as you suggested.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: RFE: find <path> -d -size 0 => doesn't find empty directories

Mark Geisert
In reply to this post by L A Walsh
L A Walsh wrote:

> Something I can use on my /tmp files on linux is a find command:
>
> find /tmp -size 0 -delete
>
> to delete zero-len-files or empty-directories in /tmp.
>
> Unfortunately, due to directories really not being in the user
> disk data space, but in the MFT(zone) (I think), the size
> comes back as zero ('0') for directories.
>
> Would it be possible (if not problematic) for the cygwin
> emulation layer to return some non-zero value if the
> directory has actual entries in it (ignoring structural
> values like "." and "..")?  Maybe return as 'size' either
> a dummy number proportional to #entries (like 10*#entries),
> or something like summing up actual number (+1) of characters
> in the file list?
>
> Would that be difficult to do, or add?

Try 'find -d -empty'

..mark


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: RFE: find <path> -d -size 0 => doesn't find empty directories

Mark Geisert
Correcting my earlier post...

Mark Geisert wrote:

> L A Walsh wrote:
>> Something I can use on my /tmp files on linux is a find command:
>>
>> find /tmp -size 0 -delete
>>
>> to delete zero-len-files or empty-directories in /tmp.
>>
>> Unfortunately, due to directories really not being in the user
>> disk data space, but in the MFT(zone) (I think), the size
>> comes back as zero ('0') for directories.
>>
>> Would it be possible (if not problematic) for the cygwin
>> emulation layer to return some non-zero value if the
>> directory has actual entries in it (ignoring structural
>> values like "." and "..")?  Maybe return as 'size' either
>> a dummy number proportional to #entries (like 10*#entries),
>> or something like summing up actual number (+1) of characters
>> in the file list?
>>
>> Would that be difficult to do, or add?
>
> Try 'find -d -empty'

I shouldn't have blindly trusted the Subject:.  My point was to use find's
'-empty' option to identify empty objects.  So...
     find . -type d -empty     to find empty directories under '.'
     find . -type f -empty     to find empty files under '.'
     find . -empty             to find empty directories or files under '.'

None of this is Cygwin-specific, by the way.  'man find' was my friend.
Cheers,

..mark


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: RFE: find <path> -d -size 0 => doesn't find empty directories

Andrey Repin
In reply to this post by L A Walsh
Greetings, L A Walsh!

> Something I can use on my /tmp files on linux is a find command:

> find /tmp -size 0 -delete

Do note that -size on directories is filesystem dependent.
I.e. on ext2+ it's the number of bytes allocated to directory structure, in
multiplies of whole blocks.

> to delete zero-len-files or empty-directories in /tmp.

> Unfortunately, due to directories really not being in the user
> disk data space, but in the MFT(zone) (I think), the size
> comes back as zero ('0') for directories.

Just as predicted.
If you want to find files, search for files.

find . -type f ...

> Would it be possible (if not problematic) for the cygwin
> emulation layer to return some non-zero value if the
> directory has actual entries in it (ignoring structural
> values like "." and "..")?  Maybe return as 'size' either
> a dummy number proportional to #entries (like 10*#entries),
> or something like summing up actual number (+1) of characters
> in the file list?

> Would that be difficult to do, or add?

Having something to this extent would be useful in case of searching for
directories with too many files, for example.

I'd vote for something like (entries << 7), which is closer to an average ext2
counter. No need to ignore anything.


--
With best regards,
Andrey Repin
Thursday, November 1, 2018 19:00:26

Sorry for my terrible english...


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: (SOLVED) RFE: find <path> -d -size 0 => doesn't find empty directories

L A Walsh
In reply to this post by Mark Geisert


On 10/31/2018 9:39 PM, Mark Geisert wrote:

>
> I shouldn't have blindly trusted the Subject:.
---
        You did and gave the right answer.  I had forgotten about
empty -- though not sure why.  I guess I usually only use it for file
normally. For empty directories under /tmp, I usually use 'rmdir *'.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: RFE: find <path> -d -size 0 => doesn't find empty directories

Brian Inglis
In reply to this post by Andrey Repin
On 2018-11-01 10:12, Andrey Repin wrote:
> L A Walsh wrote:
>> Unfortunately, due to directories really not being in the user
>> disk data space, but in the MFT(zone) (I think), the size
>> comes back as zero ('0') for directories.

>> Would it be possible (if not problematic) for the cygwin
>> emulation layer to return some non-zero value if the
>> directory has actual entries in it (ignoring structural
>> values like "." and "..")?  Maybe return as 'size' either
>> a dummy number proportional to #entries (like 10*#entries),
>> or something like summing up actual number (+1) of characters
>> in the file list?

>> Would that be difficult to do, or add?

> Having something to this extent would be useful in case of searching for
> directories with too many files, for example.

> I'd vote for something like (entries << 7), which is closer to an average ext2
> counter. No need to ignore anything.

I believe readdir(3) overhead is already high, and adding extraneous lookups to
add metadata which is not readily available under NTFS/exFAT would slow it even
further.
Do you really want readdir(3) or stat(3) to recurse to sum the entry sizes for
each subdirectory?
Some of us have some large messy directories more reminiscent of Unix systems
than typical of Windows systems.

$ time du -sh /tmp/
91M     /tmp/

real    0m5.125s
user    0m0.125s
sys     0m1.077s
$ time du -sh /var/log/
496M    /var/log/

real    0m42.725s
user    0m0.687s
sys     0m9.139s

--
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: (SOLVED) RFE: find <path> -d -size 0 => doesn't find empty directories

Mark Geisert
In reply to this post by L A Walsh
L A Walsh wrote:
> On 10/31/2018 9:39 PM, Mark Geisert wrote:
>
>>
>> I shouldn't have blindly trusted the Subject:.
> ---
>     You did and gave the right answer.  I had forgotten about
> empty -- though not sure why.  I guess I usually only use it for file
> normally. For empty directories under /tmp, I usually use 'rmdir *'.

What I meant was, I blindly trusted "-d" to select directories.  It doesn't.
One has to explicitly say '-type d' to do that.  'man find' explains.
Cheers,

..mark


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: RFE: find <path> -d -size 0 => doesn't find empty directories

Andrey Repin
In reply to this post by Brian Inglis
Greetings, Brian Inglis!

> On 2018-11-01 10:12, Andrey Repin wrote:
>> L A Walsh wrote:
>>> Unfortunately, due to directories really not being in the user
>>> disk data space, but in the MFT(zone) (I think), the size
>>> comes back as zero ('0') for directories.

>>> Would it be possible (if not problematic) for the cygwin
>>> emulation layer to return some non-zero value if the
>>> directory has actual entries in it (ignoring structural
>>> values like "." and "..")?  Maybe return as 'size' either
>>> a dummy number proportional to #entries (like 10*#entries),
>>> or something like summing up actual number (+1) of characters
>>> in the file list?

>>> Would that be difficult to do, or add?

>> Having something to this extent would be useful in case of searching for
>> directories with too many files, for example.

>> I'd vote for something like (entries << 7), which is closer to an average ext2
>> counter. No need to ignore anything.

> I believe readdir(3) overhead is already high, and adding extraneous lookups to
> add metadata which is not readily available under NTFS/exFAT would slow it even
> further.
> Do you really want readdir(3) or stat(3) to recurse to sum the entry sizes for
> each subdirectory?

If a number of directory entires is not readily available, nothing can be
done.
No recursion was intended.

> Some of us have some large messy directories more reminiscent of Unix systems
> than typical of Windows systems.

> $ time du -sh /tmp/
> 91M     /tmp/

> real    0m5.125s
> user    0m0.125s
> sys     0m1.077s
> $ time du -sh /var/log/
> 496M    /var/log/

> real    0m42.725s
> user    0m0.687s
> sys     0m9.139s



--
With best regards,
Andrey Repin
Friday, November 2, 2018 17:02:01

Sorry for my terrible english...


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple