LoginSignup
19
29

More than 5 years have passed since last update.

Windowsでtail -f

Last updated at Posted at 2015-08-06

まさにそのままのがggったらあった。

Windows で tail -f する方法 - maruko2 Note.

Get-Content コマンドレットのエイリアス[1]として cat, gc, type が登録されているので、cat でも同じ結果になる。
cat "LogFiles\Firewall\pfirewall.log" -wait -tail 10

C:\tmp> powershell
Windows PowerShell
Copyright (C) 2014 Microsoft Corporation. All rights reserved.
PS C:\tmp> cat a.txt -wait
aaaaa
aaa
aa
aa

golangではgotailというパッケージがあるらしい

$ go get github.com/ActiveState/tail
$ cp src/github.com/ActiveState/tail/cmd/gotail/gotail.go .
$ go build gotail.go
$ GOOS=windows GOARCH=amd64 go build gotail.go
$ ./gotail -h
Usage of ./gotail:
  -F=false: follow, and track file rename/rotation
  -f=false: wait for additional data to be appended to the file
  -max=0: max line size
  -n=0: tail from the last Nth location
  -p=false: use polling, instead of inotify
$ ./gotail -f a.txt
aaaaa
aaa
aa
aa

Windowsでも動く

PS C:\tmp> .\gotail.exe -h
Usage of C:\tmp\gotail.exe:
  -F=false: follow, and track file rename/rotation
  -f=false: wait for additional data to be appended to the file
  -max=0: max line size
  -n=0: tail from the last Nth location
  -p=false: use polling, instead of inotify
PS C:\tmp> .\gotail.exe -f a.txt
aaaaa
aaa
aa
aa

参考

複数ファイルの tail -f を heroku logs っぽく表示する「9t」 - Thanks Driven Life
http://gongo.hatenablog.com/entry/2015/03/09/221231
↑ソースはそんなに長くないのでgolangの勉強になる
ActiveState/tail
https://github.com/ActiveState/tail

19
29
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
29