Warning: include_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home/users/2/moriya-h5/web/confrage/unix/unix_command/find/find.html on line 2

Warning: include_once(http://www.confrage.com/bin/header.php): failed to open stream: no suitable wrapper could be found in /home/users/2/moriya-h5/web/confrage/unix/unix_command/find/find.html on line 2

Warning: include_once(): Failed opening 'http://www.confrage.com/bin/header.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/unix/unix_command/find/find.html on line 2
find | UNIX | 株式会社CONFRAGE
Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/unix/unix_command/find/find.html on line 17

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/unix/unix_command/find/find.html on line 17
find
findコマンドは、ファイルを検索するコマンドです。

ルートから検索
ファイルをファイルシステムのルートから検索する場合

find / -name a.txt
というように実行します。上記はルートからa.txtというファイルを検索し、存在する場合標準出力します。
ルートから全てのディレクトリを検索するためかなり時間がかかります。

カレントディレクトリから検索
ファイルをカレントディレクトリから検索する場合、

find . -name a.txt
というように実行します。上記はカレントディレクトリからa.txtというファイルを検索し、存在する場合標準出力します。
カレントディレクトリ配下の全てのディレクトリを検索します。

パーミッションから検索
ファイルを指定したパーミッションから検索することも出来ます。
以下のように実行します。

find . -perm 644
上記は、パーミッションが644のファイルをカレントディレクトリから検索するコマンドです。
ドット(.)は./としても同じです。

また、指定したパーミッション以上のファイルを検索したい場合は以下のようにパーミッションに-を付加します。

find ./ -perm -644
この時、複数ディレクトリを指定することも出来ます。
複数ディレクトリを指定する場合は、スペース区切りでディレクトリを指定します。

find dir1 dir2 dir3 -perm -644
ファイル更新時刻から検索
ファイルの変更時間からファイルを検索することも出来ます。
-ctimeオプションを使用し、ファイルのiノードからファイルの検索を行います。
-ctime 1 とすると、24時間以内に変更されたファイルを検索します。
-ctime 2 とすると、48時間以内に変更されたファイルを検索します。
このように指定した数値に24を掛けた時間以内に変更されたファイルを検索します。
以下は、72時間以内に変更されたファイルを検索する例です。

find / -ctime 3
検索した複数ファイルに対して別コマンドを実行
findコマンドで検索したファイルに対してそのまま別コマンドを実行したい場合、-exec {} \;オプションを使用します。
以下はカレントディレクトリ配下のJavaファイルを全て探しだし、その全ファイルに対してgrepしている例です。

find . -name "*.java" -exec grep "検索対象文字" {} \;

Back to top

Information

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/unix/unix_command/find/find.html on line 147

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/unix/unix_command/find/find.html on line 147

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/unix/unix_command/find/find.html on line 156

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/unix/unix_command/find/find.html on line 156