catコマンド
用途
ファイルの中身の閲覧や、ファイルの連結を行う
書式
cat [オプション] ファイル名s
主なオプション
ファイルの中身を閲覧(確認)する
abc def ghi jkl
mno pqr stu vwx
[devi@syslog catdir]$
表示結果に行番号をつけてみる
[devi@syslog catdir]$ cat -n file1.txt
1 abc def ghi jkl
2
3
4 mno pqr stu vwx
[devi@syslog catdir]$
[devi@syslog catdir]$ cat -b file1.txt
1 abc def ghi jkl
2 mno pqr stu vwx
[devi@syslog catdir]$
[devi@syslog catdir]$ cat -sn file1.txt
1 abc def ghi jkl
2
3 mno pqr stu vwx
[devi@syslog catdir]$
異なるファイルの内容を連結する
[devi@syslog catdir]$ cat file2.txt
abc def ghi jkl
[devi@syslog catdir]$
[devi@syslog catdir]$ cat file3.txt
mno pqr stu vwx
[devi@syslog catdir]$
[devi@syslog catdir]$ cat file2.txt file3.txt > newfile.txt
[devi@syslog catdir]$
[devi@syslog catdir]$ cat newfile.txt
abc def ghi jkl
mno pqr stu vwx
[devi@syslog catdir]$
catコマンドの便利な使い方
viをいちいち起動して内容を記述するのがメンドクサイ場合などに、
任意の文字列が出現するまで、catで出力させ、
その内容をファイルに書き込む方法があります。
毎回決まった内容を書き込む場合や、
Linuxのメモやマニュアルを記述する際に便利です。
以下では、「EOF」という文字列を終端として指定します。
これを、そのままコマンドとして流してやると、
その内容が記述されたファイルができあがります。
> 192.168.1.1 syslog.linuxtips.sblo.jp syslog
> 192.168.1.10 db1.linuxtips.sblo.jp db1
> 192.168.1.254 gw.linuxtips.sblo.jp gw
> EOF
[devi@syslog catdir]$
1 127.0.0.1 localhost.localdomain localhost
2 192.168.1.1 syslog.linuxtips.sblo.jp syslog
3 192.168.1.10 db1.linuxtips.sblo.jp db1
4 192.168.1.254 gw.linuxtips.sblo.jp gw
[devi@syslog catdir]$
タグ
2009年9月3日 | コメントは受け付けていません。 | トラックバックURL |
カテゴリー:ファイル操作系コマンド