[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Possible enhancement: file count
From: |
Fernando Pereira |
Subject: |
Re: Possible enhancement: file count |
Date: |
Mon, 29 Feb 2016 17:35:10 +0100 |
Thanks for the very informative answer! I expected the piping of all the
filenames to another program to incur much higher overhead.
Anyway I'm glad to see that the new du can count inodes, hopefully faster
for when we can give up flexibility.
Cheers,
Fernando
On 29 February 2016 at 17:28, Assaf Gordon <address@hidden> wrote:
> Hello Fernando,
>
> On 02/29/2016 10:48 AM, Eric Blake wrote:
>
>> On 02/29/2016 08:23 AM, Fernando Pereira wrote:
>>
>> Anyway, I was looking for the most efficient way to do that and I couldn't
>>> find satisfying answer.
>>>
>>
>> But 'find | wc' IS efficient, and already exists on every machine,
>>
>
> Additionally, once you start drilling-down to find more detailed
> information about the usage, you'll likely need find's features anyhow:
>
> Few examples (since you've mentioned 'small files'):
>
> find files smaller than 10K:
>
> find . -type f -size -10K
>
> find files larger than 1G:
>
> find . -type f -size +1G
>
> find empty files:
>
> find . -type f -size 0
>
> find files of specific extension:
>
> find . -type f -iname '*.mp4'
>
> Similarly, you can use find to find files that have not been modified in
> the last X days,
> or created less than 24 hours ago, etc. etc.
>
> A useful utility to investigate file sizes will end-up re-implementing
> many of these fine-grained predicates.
>
> I would recommend learning how to use 'find' to its full potential, then
> for the most commonly-used operation,
> either create a small shell script, or a shell alias.
> A brief tutorial: http://crashcourse.housegordon.org/find-and-delete.html
>
> Example, the following alias will list files larger than 1G, with the
> size, owner, and path:
>
> alias find_large_files='find . -type f -size +1G -printf
> "%s\t%u\t%p\n" 2>/dev/null'
>
> Using find in combination of other programs will allow you greater
> flexibility in finding the information you need.
>
> Example, this will print the number of files owned by each user:
>
> $ sudo find /home -type f -printf "%u\t%f\0" 2>/dev/null \
> | sort -z | datamash -z --group 1 count 2 \
> | tr '\0' '\n' | numfmt --field=2 --to=iec
>
> (note: numfmt is available since coreutils 8.21, and gnu datamash is
> available here: http://gnu.org/s/datamash/ ).
>
> If you need more information, consider using one of the graphical programs
> to display 'tree map' view of your directories
> (e.g. https://wiki.gnome.org/Apps/Baobab or https://dev.yorhel.nl/ncdu ).
>
> regards,
> - assaf
>