less でオプション使ってみる
Unix
Published: 2019-10-09

やったこと

less でログを見やすくするオプションを試しました。

調査

例えば、Rails のログをみるとします。

$ less log/development.log

Started GET "/" for ::1 at 2019-10-09 23:04:28 +0900
path is other
Processing by TasksController#index as HTML
  ESC[1mESC[36mTask Load (1.3ms)ESC[0m  ESC[1mESC[34mSELECT  "tasks".* FROM "tasks" WHERE "tasks"."id" = ? LIMIT ?ESC[0m  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/tasks_controller.rb:7
  Rendering tasks/index.html.erb within layouts/application
  Rendered tasks/index.html.erb within layouts/application (1.8ms)
Completed 200 OK in 92ms (Views: 60.4ms | ActiveRecord: 1.8ms)

-qR オプションつき

$ less -qR log/development.log

Started GET "/" for ::1 at 2019-10-09 23:04:28 +0900
path is other
Processing by TasksController#index as HTML
  Task Load (1.3ms)  SELECT  "tasks".* FROM "tasks" WHERE "tasks"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/tasks_controller.rb:7
  Rendering tasks/index.html.erb within layouts/application
  Rendered tasks/index.html.erb within layouts/application (1.8ms)
Completed 200 OK in 92ms (Views: 60.4ms | ActiveRecord: 1.8ms)

おまけ

ESC という文字が消えています。

-q は、ビープ音を鳴らさなくします。 -R は、ANSI Escape sequences をカラー表示します。

$ man less

> -q or --quiet or --silent
> -R or --RAW-CONTROL-CHARS