[TAG] [2 cents TIP] efficient use of "-exec" in find
Ben Okopnik
ben at linuxgazette.net
Mon Feb 1 19:04:27 MSK 2010
On Mon, Feb 01, 2010 at 08:59:12AM +0000, Neil Youngman wrote:
> On Monday 01 February 2010 02:49:23 Ben Okopnik wrote:
> > You're right - I missed that. What is the point of using 'du -k' at all,
> > if all you're trying to do is get the size of the file? Seems to me
> > that 'find ~ -type f -ls' or maybe 'find ~ -type f -printf "%k\t%f\n"'
> > would do everything you need.
>
> Well du -k and find -ls will usually give completely numbers, e.g.
I'm quite aware of that. That's why I gave the second solution - just in
case Mulyadi wanted the number of blocks instead of the filesize.
> Experienced users will be aware that a file consists of a series of blocks and
> a whole block is allocated whenever there is insufficient space allocated for
> data written to the file. As a result, a whole block will be allocated on
> disk for a 1 byte file and as a block on my filesystem is 4kB that means that
> a single file uses up 4kB of disk space, as reported b "du -k", although it
> only contains 1 byte of data, as shown by "find -ls".
Please watch carefully; the special effects are quite expensive. :)
```
ben at Jotunheim:~$ mkdir /tmp/foo; echo > /tmp/foo/x
ben at Jotunheim:~$ du -k /tmp/foo/x
4 /tmp/foo/x
ben at Jotunheim:~$ find /tmp/foo -name x -printf "%k\t%h/%f\n"
4 /tmp/foo/x
'''
--
* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *
More information about the TAG
mailing list