2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PowerShellでファイルの中身をサクッと確認するTips:`Get-Content` × `-Tail`

Last updated at Posted at 2025-03-30

概要

ログファイルや設定ファイルをチェックする際、「テキストエディタを開くのが面倒」「とりあえず中身だけ確認したい」という場面は多い。
特に開発中やデバッグ中など、素早く情報にアクセスしたいときには、エディタよりCLIの方が圧倒的に速い。

本記事では、PowerShellでファイルの中身を即座に確認するためのコマンドを紹介する。


対象環境

OS   : Windows 10 / 11  
Shell: PowerShell 5.x / 7.x  

基本構文

Get-Content .\path\to\file.txt

ファイルの中身を行単位で標準出力に表示する。


応用:末尾のみ確認したいとき(ログ確認に最適)

Get-Content .\app.log -Tail 20

-Tailオプションを使うことで、ファイル末尾のn行だけを取得できる。ログ確認においてはほぼ必須と言っていい。


リアルタイムでログ監視(tail -f 的に)

Get-Content .\app.log -Wait
  • -Waitを付けると、ファイルの更新を監視しつつリアルタイムで出力される。
  • tail -f 相当の動作。

組み合わせ例:末尾20行だけ + 監視モード

Get-Content .\app.log -Tail 20 -Wait

これは最強のログ確認コマンド。実運用に即投入できる。


補足:エイリアスでもっと短く書く

gc .\app.log -Tail 10

Get-Contentgcのエイリアスでもあるため、短縮して書ける。
PowerShellならではの柔軟さが光る。


結語

「テキストファイルを開く」という行為に、GUIエディタを起動する必要はない。
PowerShellの Get-Content は、"今すぐ見たい" を叶える最短ルートだ。

ログ、設定ファイル、結果出力、すべてに使えるユーティリティ。
CLIから高速でプレビューする習慣を持てば、あなたの開発速度は確実に一段上がる。

2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?