[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: file size utility



Jacob,

On Thu, 9 Jun 2005, Jacob Fugal wrote:
> I know how to use "find" to get a list of files I want, but now I need
> to get the total size of all those files. Do I need to write a script or
> is there a command to do this in Linux? Again, I need to sum the total
> size of all the files matching a certain pattern (like *.png)
> recursively below some directory.

Here is a fun one:
du -ha | grep -i "\.png"

What this does is generate a listing of the sizes of *all* the files and
then filters out those which have .png in it's name.  (The `i' is for case
insensitivity)

An advantage of this from using the `find...` syntax is that it doesn't
give an argument overflow when your looking at large numbers of files, and
the time is relatively the same since querying a file / directory for the
file handles and querying with a request for size is relatively the same
amount of cost.

- Paul Schou
Guardian of Data

--
<pre>
%{---------------------------------------------------------------------+
 | Paul Schou                                            paulschou.com |
 |   Physics and Mathematics                                           |
 | Michigan Technological University           Houghton, MI 49931, USA |
 |   University Web Designer / Programmer / Databases      www.mtu.edu |
 |   N.I.T.E. President                  www.admin.mtu.edu/stuact/nite |
 |   CAEL Partner - Senior                www.me.mtu.edu/cael/partners |
 |   CCLI Consultant - Lab Asst                    www.hu.mtu.edu/ccli |
 |   Future Truck                                  www.me.mtu.edu/~fcc |
 |   LUG - Linux Users Group (co-founder)                  lug.mtu.edu |
 | NVG - Network Users Group                   www.nvg.ntnu.no/~pschou |
 +---------------------------------------------------------------------%}
</pre>