grep コマンドで複数ファイルから検索
* というワイルドカードを使うことで
複数ファイルの中から該当する部分を表示することができる
今回は centos の key ファイルの場所について調べたいので
まずは config ファイルを調べる
1 | ll /etc/ssh/ *config |
すると該当するのが2つある
1 2 | -rw-r--r--. 1 root root 2047 11月 13 17:54 2014 /etc/ssh/ssh_config -rw-------. 1 root root 3913 3月 7 20:54 2014 /etc/ssh/sshd_config |
本来なら
1 2 | cd /etc/ssh sudo grep key ssh_config sshd_config |
というように
ファイルを2つ指定して行うけど
もっとたくさんの設定ファイルになってくると
これは非効率的
なので *をつかって複数ファイルを対象に調べる
1 | sudo grep key /etc/ssh/ *config |
結果はどちらでも同じになる
1 2 3 4 5 6 7 8 | /etc/ssh/sshd_config : #HostKey /etc/ssh/ssh_host_key /etc/ssh/sshd_config : #HostKey /etc/ssh/ssh_host_rsa_key /etc/ssh/sshd_config : #HostKey /etc/ssh/ssh_host_dsa_key /etc/ssh/sshd_config : # Lifetime and size of ephemeral version 1 server key /etc/ssh/sshd_config : #PubkeyAuthentication yes /etc/ssh/sshd_config : #AuthorizedKeysFile .ssh/authorized_keys /etc/ssh/sshd_config : # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts /etc/ssh/sshd_config : # Change to no to disable s/key passwords |
このワイルドカードと呼ばれる*の一斉検索は
ソースコードなどをみるときにも使える
また、 -r オプションで検索すれば
ファイル名ではなく、ディレクトリを指定して調べることもできる
例えば
wordpress の投稿内容を表示する
the_content
をテーマのどこにあるか調べるのなら
1 | grep -r the_content /var/www/html/wordpress/wp-content/themes/twentyfifteen/ |
とすれば
1 2 3 4 5 | /var/www/html/wordpress/wp-content/themes/twentyfifteen/content-page .php: <?php the_content(); ?> /var/www/html/wordpress/wp-content/themes/twentyfifteen/content-link .php: the_content( sprintf( /var/www/html/wordpress/wp-content/themes/twentyfifteen/inc/template-tags .php: $has_url = get_url_in_content( get_the_content() ); /var/www/html/wordpress/wp-content/themes/twentyfifteen/image .php: the_content(); /var/www/html/wordpress/wp-content/themes/twentyfifteen/content .php: the_content( sprintf( |
という結果になる
なお、ソースコードを調べる場合
量がおおいときもあるので
そんなときには
less コマンドをつかうと見やすくなる