views:

959

answers:

5

Hi,

this command is really very useful but where I can get the source code to see what is going on inside .

thanks .

+2  A: 

After doing a quick search, this is one of the first things I found.

Daniel Pryden
That is a horribly old piece of software that bundles an equally outdated Busybox. Modern versions including bugfixes are available at http://www.busybox.net/downloads/.
daxim
+5  A: 

Look here — http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/tail.c

Michael Krelin - hacker
To build this, you are also going to need the rest of the coreutils package.
Matt Beldyk
Of course. It's easy to travel up the tree starting from there.
Michael Krelin - hacker
But it is my understanding that the OP is driven by curiosity not the need of utility which is available out of the box more or less everywhere.
Michael Krelin - hacker
+1  A: 

Poke around the uclinux site. Since they distributed the software, they are required to make the source available one way or another.

Or, you could read man fseek and guess at how it might be done.

NB-- See William's comments below, there are cases when you can't use seek.

dmckee
tail does not use fseek. If it did, it would not work on a stream (eg 'grep pat file | tail')
William Pursell
Hmm, never thought of that. Thanks. I have to think that it would still be faster when working with seekable input.
dmckee
This is not exactly true. `tail` doesn't *always* use seek ;-)
Michael Krelin - hacker
+6  A: 

The tail utility is part of the coreutils on linux.

I've always found FreeBSD to have far clearer source code than the gnu utilities. So here's tail.c in the FreeBSD project:

Stef
+1 for diversity, even though the original question was about linux utility.
Michael Krelin - hacker
A: 

You might find it an interesting exercise to write your own. The vast majority of the Unix command-line tools are a page or so of fairly straightforward C code.

To just look at the code, the GNU CoreUtils sources are easily found on gnu.org or your favorite Linux mirror site.

Mark Bessey
I wrote a fairly complete set of tools for MS-DOS back when Linux was in its infancy. And while many are certainly straight forward, I would hesitate to say "a page' and wouldn't say a "vast majority". **find** and **ls** for example, were considerably more complex.
NVRAM
The core of most of the tools generally *is* short. But the argument processing and corner case handling can be a pain.
dmckee
Mark Bessey