Skip to content

tailFile

Requires a Node.js runtime ('qsu/node')

Returns the last line of the specified text file path. The length argument is the total number of lines to print. Default is 1. The last line of newline characters is ignored.

The file is read backwards from its end, a chunk at a time, until the requested lines are in hand. The cost follows the number of lines asked for rather than the size of the file, so the last line of a 10 GB log costs the same as the last line of a small one.

A line breaks on \n, \r\n or a lone \r. Bytes that are not valid UTF-8 become the replacement character U+FFFD instead of raising, and a leading byte order mark is kept.

Parameters

NameTypeRequiredDefault
filePathstringStringstr
File or directory path
lengthnamedkeywordnumberint1
Number of lines of text to return

namedThese parameters are passed as named parameters.

keywordThese parameters are passed as keyword arguments, or as a single dict in their place.

Returns

Promise<string | null>

Future<String?>

str | None

Examples

javascript
await tailFile('/home/targets/hello.md', 2); // 'Good bye\n--- Hello End ---'
dart
await tailFile('/home/targets/hello.md', length: 2); // 'Good bye\n--- Hello End ---'
python
tailFile('/home/targets/hello.md', 2) # 'Good bye\n--- Hello End ---'

Released under the MIT License