Linux-admin-cut-command
提供:Dev Guides
Linux Admin-cutコマンド
*cut* と *grep* は、CentOS管理者にとって最も便利で一般的なコマンドの2つです。 cutは、Linux構成ファイル、Linux設定ファイル、CSVファイルなどの区切りファイルを扱うのに非常に便利です。
| Switch | Action |
|---|---|
| -b | Select only these bytes |
| -c | Select only these characters |
| -d | Use DELIM instead of TAB for field delimiter |
| -s | Only print delimited lines |
ほとんどの場合、_cut_はテキストファイルから特定の行を抽出するために使用されます。 以前は、_cut_を使用して/etc/passwdからすべてのユーザーのリストを取得しました-
[root@centosLocal centos]# cut -d":" -f1/etc/passwd
root
bin
daemon
adm
lp
sync
shutdown
上記は/etc/passwdのシステムユーザーの要約リストです。
一部のLinuxユーティリティおよびアプリケーションは、実際に_cut_の機能を考慮して出力を保存します。 以下は、nmap出力の例です。
[root@centosLocal centos]# grep open ./http_scans.txt
Host: 10.58.52.67 () Ports: 80/open/tcp//http///
Host: 10.58.52.132 () Ports: 80/open/tcp//http///
Host: 10.58.52.133 () Ports: 80/open/tcp//http///
Host: 10.58.52.56 () Ports: 80/open/tcp//http///
Host: 10.58.52.71 () Ports: 80/open/tcp//http///
Host: 10.58.52.132 () Ports: 80/open/tcp//http///
_cut_を使用すると、外部要求をリッスンするポート80を持つ内部システムのリストをすばやく生成できます。
[root@centosLocal centos]# grep open ./http_scans.txt | cut -d" " -f2 >
open_http_servers.txt
[root@centosLocal centos]# head open_http_servers.txt
10.58.52.17
10.58.52.29
10.58.52.30
10.58.52.36
10.58.52.59
10.58.53.89
10.58.53.100
10.58.54.103
10.58.54.148
10.58.54.152
[root@centosLocal centos]#
カットは、文字カウントでも使用できます。
[root@centosLocal centos]# cut -c 1,2,3,4,5,6,7,8 lanIP-range.txt
10.58.52
10.58.52
10.58.52
10.58.52
10.58.52
10.58.52
10.58.53
10.58.53
10.58.53
10.58.53
10.58.53
10.58.54
10.58.54
10.58.54
10.58.54
10.58.54
10.58.54
10.58.54
10.58.54
10.58.54
10.58.54
10.58.54
10.58.54
10.58.54
10.58.54
10.58.54
10.58.54
[root@centosLocal centos]#
_cut_は、CentOS管理者がほぼ毎日使用するコマンドです。 テキストといくつかのバイナリファイルを解析するための命の恩人です。