概要
catコマンドは、テキストファイルを表示したり連結したりするためのコマンドです。
※concatenate(連結する)の略
dir
└─ sample.txt
===============
【sample.txtに中身】
このテキストはサンプルテキストになります。
これはテキストの内容です。
【dirディレクトリにいる場合】
[tomoji@10moji-blog.com dir]$ cat sample.txt
このテキストはサンプルテキストになります。
これはテキストの内容です。複数のファイル連結
dir
├─ sample1.txt
└─ sample2.txt
===============
【sample1.txtに中身】
これはテキスト1の内容です。
【sample2.txtに中身】
これはテキスト2の内容です。
【dirディレクトリにいる場合】
[tomoji@10moji-blog.com dir]$ cat sample1.txt sample2.txt
これはテキスト1の内容です。
これはテキスト2の内容です。別ファイルにリダイレクト
dir
├─ sample1.txt
└─ sample2.txt
===============
【sample1.txtに中身】
これはテキスト1の内容です。
【sample2.txtに中身】
これはテキスト2の内容です。
【dirディレクトリにいる場合】
[tomoji@10moji-blog.com dir]$ cat sample1.txt sample2.txt > combined_sample.txt
[tomoji@10moji-blog.com dir]$ cat combined_sample.txt
これはテキスト1の内容です。
これはテキスト2の内容です。複数ファイルを一括連結
dir
├─ sample1.txt
├─ sample2.txt
└─ sample3.txt
===============
【sample1.txtに中身】
これはテキスト1の内容です。
【sample2.txtに中身】
これはテキスト2の内容です。
【sample3.txtに中身】
これはテキスト3の内容です。
【dirディレクトリにいる場合】
[tomoji@10moji-blog.com dir]$ cat *.txt > combined_sample.txt
[tomoji@10moji-blog.com dir]$ cat combined_sample.txt
これはテキスト1の内容です。
これはテキスト2の内容です。
これはテキスト3の内容です。オプション一覧
| オプション | 説明 |
|---|---|
| -n | 行番号表示 |
| -b | 行番号を表示(空行除外) |
| -s | 連続する空行を一つの空行集約 |
| -E | 各行末尾に$表示 |
| -T | タブ文字を^Iとして表示 |
-n
-nオプションは、行番号を表示します。
dir
└─ sample1.txt
===============
【sample1.txtに中身】
これはテキスト1の内容です。
これはテキスト1の内容です。
これはテキスト1の内容です。
これはテキスト1の内容です。
【tomojiディレクトリにいる場合】
[tomoji@10moji-blog.com dir]$ cat -n sample1.txt
1 これはテキスト1の内容です。
2 これはテキスト1の内容です。
3 これはテキスト1の内容です。
4 これはテキスト1の内容です。-b
-bオプションは、行番号を表示しますが空行には番号を付けません。
dir
└─ sample1.txt
===============
【sample1.txtに中身】
これはテキスト1の内容です。
これはテキスト1の内容です。
【tomojiディレクトリにいる場合】
[tomoji@10moji-blog.com dir]$ cat -n sample1.txt
1 これはテキスト1の内容です。
2
3 これはテキスト1の内容です。
[tomoji@10moji-blog.com dir]$ cat -b sample1.txt
1 これはテキスト1の内容です。
2 これはテキスト1の内容です。-s
-sオプションは、連続する空行を一つの空行に縮約します。
dir
└─ sample1.txt
===============
【sample1.txtに中身】
これはテキスト1の内容です。
これはテキスト1の内容です。
これはテキスト1の内容です。
【dirディレクトリにいる場合】
[tomoji@10moji-blog.com dir]$ cat sample1.txt
これはテキスト1の内容です。
これはテキスト1の内容です。
これはテキスト1の内容です。
[tomoji@10moji-blog.com dir]$ cat -s sample1.txt
これはテキスト1の内容です。
これはテキスト1の内容です。
これはテキスト1の内容です。-E
-Eオプションは、各行の末尾に$を表示します。
dir
└─ sample1.txt
===============
【sample1.txtに中身】
これはテキスト1の内容です。
これはテキスト1の内容です。
【dirディレクトリにいる場合】
[tomoji@10moji-blog.com dir]$ cat -E sample1.txt
これはテキスト1の内容です。$
これはテキスト1の内容です。$-T
-Tオプションは、タブ文字を^Iとして表示します。
dir
└─ sample1.txt
===============
【sample1.txtに中身】
s a m p l e 1
【dirディレクトリにいる場合】
[tomoji@10moji-blog.com dir]$ cat sample1.txt
s a m p l e 1
[tomoji@10moji-blog.com dir]$ cat -T sample1.txt
s^Ia^Im^Ip^Il^Ie^I1