0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windowsでhead、tailが使いたい

Posted at

WindowsとLinux系のOSをどちらも利用していると、
色々なコマンドなり機能なりで、あっちにこれがあったら良いのにな、
と思うことがあるかなと思います。

今回はそのうちの一つで、「Windowsでhead、tailが使いたい」という要望を、
状況に応じてアプローチの整理をしてみました。

アプローチの整理

フローチャートの解説

  • インターネットが利用可能か、インストールが可能か
    • 可能なら、既存のツールを導入するのが簡単。
    • 不可能なら、Windows標準機能で実装する必要がある。
  • 既存のツールを導入
    • Linux環境を整える(WSL) → Ubuntuなどを使い、head / tailをそのまま実行可能。
    • 新しいターミナルを導入 → Git Bash、Cmder、MSYS2をインストールし、Unixコマンドを使う。
    • 最小限のUnixコマンドを追加 → GNU CoreutilsやBusyBoxでhead / tailだけを追加。
  • 標準機能で実装
    • スクリプトを作成 → PowerShell(Get-Content)、バッチ(for /F + more)、VBScriptで代替機能を実装。
    • コンパイル済みアプリを用意 → 対象端末にコンパイル環境があれば、C / C++でhead / tailを作成し、MinGWやVisual Studioでコンパイル。他言語でも実装は可能。

おすすめ

  • 簡単に使いたい → WSL / Git Bash / Cmder
  • 軽量に導入したい → GNU Coreutils / BusyBox
  • スクリプトで対応したい → PowerShell / Batch
  • 完全にWindows標準でやりたい/やらねばならぬ → Batch / VBScript
  • C / C++ で学習したい → MinGWやVisual Studioで開発

標準のコマンドプロンプトでやってみる、という場合は以下をご利用ください。

https://qiita.com/kubo4ka/items/3ff8d00f2e1cdb0431cd

個人的には履歴機能あって、ぱっと見使いやすいのでcmder導入が好きです。
GitBashも勿論良いと思います。
クイズ的な感じでコマンドプロンプトで実装するのは楽しかったです。
ただ、ファイルサイズ大きいものには向かないとか、問題あるので、
可能なら素直に何らかのツール導入が良いかと思います。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?