Dtail [ -number-of-records ] [ input-file.. ]
Dtail selects the last number-of-records records from each input-file. If an input file has less than the -number-of-records records, all the records of that file are selected. (It does not affect to the next input file).
When there are more than one input-files, "filename:" field is added to each output record unless the input file is not standard input.
When the number-of-records parameter is not given, 1 is assumed.
Select the last records from each ".d" files.
Dtail *.d
Select the last five records from "foo.d" file.
Dtail -5 list.d
Select the tenth from the last record of "bar.d" file.
Dtail -10 bar.d | Dhead
Selecting tail records is not simple job. This is proved by the fact that the source program of GNU "tail" spends more than one and a half thousand lines, while the source program of GNU "head" is less than five hundred lines.
Main reason is, of course, you can not read a file backwards. You may read disk files from the last block, if you know the file size, and you can jump to a certain position in a file. But, this is not possible if your input file is terminal.
Moreover, tail command supports "follow" mode which continuously monitors the growth of file. This is useful when you want to fetch the latest information from a log file.
Dtail, however, does not support "follow" mode or any other options (but the number of records) which the tail command supports. Dtail has, as other D-commands, quite simple function. But, still, it can not avoid the difficulties of backward counting.
Dtail's solution for backward counting is again quite simple and general but in some cases considerably slow one. It reads the input records from the top, and always keeps the last number-of-records records in the first-in-first-out queue on the memory. When it encounters the end of file, these queued records are output.
This algorithm is simple and general, because it works on any file including standard input, and thus makes the source program considerably short. On the other hand, it makes the program slow, because the program has to read whole records even for the last one record. In addition, it requires large memory because the program has to keep number-of-records records in the memory, and you always have to read in and keep the maximum length record at least for a while.
Backward searching for D-record boundaries may be possible for disk files, and it must improve the speed. Requirements for such improvement may be considered in the future versions.
See the manual of D_msg.
MIYAZAWA Akira