[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Possible enhancement: file count
From: |
Assaf Gordon |
Subject: |
Re: Possible enhancement: file count |
Date: |
Mon, 29 Feb 2016 11:28:38 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 |
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