Skip to main content

文件tail工具。引入“偏移量文件”记录文件读取信息,支持文件内容断续读取。

Project description

tail

文件tail工具。引入“偏移量文件”记录文件读取信息,支持文件内容断续读取。

安装

pip install tail

安装的命令

  • pytail

注意:

  • 在python模块、方法中,均使用tail名称。
  • tail是linux的常用命令,一般发行版中必然都已经安装。
  • 提供的console程序,命名为pytail,防止这种冲突。

命令帮忙信息

E:\tail>pytail --help
Usage: tail [OPTIONS] FILENAME

  文件tail工具。引入“偏移量文件”记录文件读取信息,支持文件内容续读。

Options:
  -o, --offset-file TEXT          偏移量文件路径。默认为:在文件名后加.offset后缀。
  -x, --read-from-end             如果不存在偏移量文件的话,指定该参数后则从文件的最后开始读取;不指定该参数的话则从文件开
                                  始读取。
  -e, --file-encoding TEXT        文件读取编码,默认为utf-8。
  -p, --backup-patterns TEXT      文件可能通过logrotate等方式被备份出来,通过inode识别这些文件,先读取完备份
                                  文件中的剩余内容,再读取新文件内容。
  -s, --sleep-interval INTEGER    读完文件后,休息一段时间后再续读。休息时间单位为:秒,默认为1秒。
  -u, --update-offset-every-n INTEGER
                                  每读取指定行后,更新偏移量文件。默认为100行。
  -n, --non-blocking              指定该参数后,表示读取完文件内容后直接退出,同时sleep-
                                  interval参数无效;不指定的话则休眠sleep-interval秒后重新续读。
  --help                          Show this message and exit.

命令安全案例

E:\tail>type a.txt
line 1
line 2
line 3

E:\tail>pytail -n a.txt
line 1
line 2
line 3

E:\tail>echo line 4 >> a.txt

E:\tail>echo line 5 >> a.txt

E:\tail>pytail -n a.txt
line 4
line 5
  1. 读取a.txt全部文件内容并显示,读完后退出,生成a.txt.offset偏移量文件。
  2. 在a.txt中追加line 4、line 5两行内容。
  3. 根据a.txt.offset偏移量文件进行续读,显示第4、5两行。

tail模块公开的类、方法

  • TailReader 核心文件处理类。
  • print_line 行处理方法。在屏幕上打印行,文件readline后的带上的\r\n字符。
  • tail TailReader的包装方法。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tail-0.1.12.tar.gz (5.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page