1
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?

More than 5 years have passed since last update.

headコマンド

Posted at

headはファイルの中身を指定行だけ参照できる。(catの軽い版?)

$ head [option] [filename]

これだけ。デフォルトで10行表示。

# 普通に表示
$ head hoge.rtf

# パス指定
$ head /test/hoge.rtf

# 拡張子指定
$ head *.rtf

複数の表示も可能。スペースで繋ぐだけ。

$ head hogehoge.rtf huga.py

行数の指定はoptionで指定。(文字数指定等のoptionも存在しているが使わなそう...?)

# 行数指定
$ head -n 3 hogehoge.rtf       /*  3行のみ出力  */

# 'n'option使わずにこれでもOK
$ head -3 hogehoge.rtf       /*  3行のみ出力  */

xargsで検索拡張。

# 現階層におけるrtfファイルの中身に'2'が含まれるもの
$ find . -name "*.rtf" | xargs head -n 2

# これでも同義
$ find . -name "*.rtf" | xargs head -2


# 上記の条件に'-L'optionで1ファイルごとの確認を追加
$ find . -name "*.rtf" | xargs -L1 -p head -n 2
1
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
1
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?