public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* RFE: find <path> -d -size 0 => doesn't find empty directories
@ 2018-10-31 23:02 L A Walsh
  2018-11-01  0:02 ` Norton Allen
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: L A Walsh @ 2018-10-31 23:02 UTC (permalink / raw)
  To: cygwin

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: RFE: find <path> -d -size 0 => doesn't find empty directories
  2018-10-31 23:02 RFE: find <path> -d -size 0 => doesn't find empty directories L A Walsh
@ 2018-11-01  0:02 ` Norton Allen
  2018-11-01  1:16 ` Mark Geisert
  2018-11-01 16:20 ` Andrey Repin
  2 siblings, 0 replies; 9+ messages in thread
From: Norton Allen @ 2018-11-01  0:02 UTC (permalink / raw)
  To: cygwin

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: RFE: find <path> -d -size 0 => doesn't find empty directories
  2018-10-31 23:02 RFE: find <path> -d -size 0 => doesn't find empty directories L A Walsh
  2018-11-01  0:02 ` Norton Allen
@ 2018-11-01  1:16 ` Mark Geisert
  2018-11-01  4:40   ` Mark Geisert
  2018-11-01 16:20 ` Andrey Repin
  2 siblings, 1 reply; 9+ messages in thread
From: Mark Geisert @ 2018-11-01  1:16 UTC (permalink / raw)
  To: cygwin

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: RFE: find <path> -d -size 0 => doesn't find empty directories
  2018-11-01  1:16 ` Mark Geisert
@ 2018-11-01  4:40   ` Mark Geisert
  2018-11-01 16:27     ` (SOLVED) " L A Walsh
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Geisert @ 2018-11-01  4:40 UTC (permalink / raw)
  To: cygwin

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: RFE: find <path> -d -size 0 => doesn't find empty directories
  2018-10-31 23:02 RFE: find <path> -d -size 0 => doesn't find empty directories L A Walsh
  2018-11-01  0:02 ` Norton Allen
  2018-11-01  1:16 ` Mark Geisert
@ 2018-11-01 16:20 ` Andrey Repin
  2018-11-02  5:05   ` Brian Inglis
  2 siblings, 1 reply; 9+ messages in thread
From: Andrey Repin @ 2018-11-01 16:20 UTC (permalink / raw)
  To: L A Walsh, cygwin

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: (SOLVED) RFE: find <path> -d -size 0 => doesn't find empty directories
  2018-11-01  4:40   ` Mark Geisert
@ 2018-11-01 16:27     ` L A Walsh
  2018-11-02  5:33       ` Mark Geisert
  0 siblings, 1 reply; 9+ messages in thread
From: L A Walsh @ 2018-11-01 16:27 UTC (permalink / raw)
  To: cygwin



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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: RFE: find <path> -d -size 0 => doesn't find empty directories
  2018-11-01 16:20 ` Andrey Repin
@ 2018-11-02  5:05   ` Brian Inglis
  2018-11-02 14:05     ` Andrey Repin
  0 siblings, 1 reply; 9+ messages in thread
From: Brian Inglis @ 2018-11-02  5:05 UTC (permalink / raw)
  To: cygwin

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: (SOLVED) RFE: find <path> -d -size 0 => doesn't find empty directories
  2018-11-01 16:27     ` (SOLVED) " L A Walsh
@ 2018-11-02  5:33       ` Mark Geisert
  0 siblings, 0 replies; 9+ messages in thread
From: Mark Geisert @ 2018-11-02  5:33 UTC (permalink / raw)
  To: cygwin

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: RFE: find <path> -d -size 0 => doesn't find empty directories
  2018-11-02  5:05   ` Brian Inglis
@ 2018-11-02 14:05     ` Andrey Repin
  0 siblings, 0 replies; 9+ messages in thread
From: Andrey Repin @ 2018-11-02 14:05 UTC (permalink / raw)
  To: Brian Inglis, cygwin

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-11-02 14:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-31 23:02 RFE: find <path> -d -size 0 => doesn't find empty directories L A Walsh
2018-11-01  0:02 ` Norton Allen
2018-11-01  1:16 ` Mark Geisert
2018-11-01  4:40   ` Mark Geisert
2018-11-01 16:27     ` (SOLVED) " L A Walsh
2018-11-02  5:33       ` Mark Geisert
2018-11-01 16:20 ` Andrey Repin
2018-11-02  5:05   ` Brian Inglis
2018-11-02 14:05     ` Andrey Repin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).