cat

ファイルとディレクトリ

書き方

cat [file...]

ファイルを続けてそのまま出します。一気に流すので長いファイルは less が向き、cat file | grep はパイプが一本余ります。

よく使うオプション

オプション意味
-nNumber every line
-bNumber only the non-blank lines
-sSqueeze runs of blank lines into one
-vShow non-printing characters
-eBSD: -v plus a $ at each line end; GNU spells this -A

cat a.txt b.txt > all.txt

Joins two files into one.

cat -n script.sh

Prints it with line numbers.

cat > note.txt

Types a new file from the keyboard until Ctrl-D.

移したり消したり探したりするものです。聞き返してくれない命令が混ざっているので、-i を付ける癖が手を守ります。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. cat は何をしますか。

ファイルを続けてそのまま出します。一気に流すので長いファイルは less が向き、cat file | grep はパイプが一本余ります。

Q. どう打ちますか。

cat [file...] — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは5個です。全部は man cat にあります。このコマンドはファイルとディレクトリの仲間です。

関連するコマンド

man ページ: man cat