stat
system call. I've
written a program, distance.c
,
that you can use to find this difference for any file.
To find these inode distances for all the normal files under
/tmp/src
, sorted into numerical order, you could use
the following command
find /tmp/src -type f -exec ./distance '{}' ';' | sort -g >/tmp/filedists(Note that the option to
sort
is -g
because
of a bug in the version of sort
we have installed. If
sort
weren't buggy, the option -n
would be a
better choice.)
You can find the range of distances by looking at the first and last
line of the file, with the commands
head -1 /tmp/filedists tail -1 /tmp/filedistsNote that the first argument to
head
and
tail
has a hyphen followed by the number 1, which
indicates that we want to see 1 line of the file (the first 1 or the
last 1).
You might also be interested in the median value, which you can find
by selecting out the middle line First use
wc -l /tmp/filediststo count the number of lines; this time the character after the hyphen is the letter l, indicating that it we want to count lines (as opposed to words or characters). Then use a combination of
head
piped into tail
to select out the middle line. (Use
head
to select out the first half of the file, rather
than just the first line, and then use tail
to select out
the last line of that first half.)
You can find the range and median of the inode distances for
directories similarly, but using d
rather than
f
for the -type
option to the
find
command.
Instructor: Max Hailperin