find(1)
Post on 24-May-2015
1.953 Views
Preview:
DESCRIPTION
TRANSCRIPT
1findfind
main.cfind.coption.coperator.cls.cfunction.cmisc.c
main.cfind.coption.coperator.cls.cfunction.cmisc.c
2main(int argv, char **argc)
main.cmain(int argv, char **argc)
main.c
int find_execute(PLAN *plan, char *paths[])find.c
int find_execute(PLAN *plan, char *paths[])find.c
PLAN *find_formplan(char *argv[])find.c
PLAN *find_formplan(char *argv[])find.c
PLAN *find_create(char ***argvp)option.c
PLAN *find_create(char ***argvp)option.c
OPTION *lookup_option(const char *name)option.c
OPTION *lookup_option(const char *name)option.c
int typecompare(const void *a, const void *b)option.c
int typecompare(const void *a, const void *b)option.c
2.PLAN* の作成2.PLAN* の作成
3.PLAN* の実行3.PLAN* の実行
findの構造findの構造
1.オプションの解析1.オプションの解析
31.オプションの解析1.オプションの解析
オプション⇒"EHLPXdf:sx"usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression] find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]
Manpageよりfind ユーティリティは、 pathname に対してディレクトリ
ツリーを再帰的に下って、ツリー上の各ファイルについて
expression (後に示す``プライマリ''と``演算子'' から構
成されます) で指定された処理を実行します。
オプション⇒"EHLPXdf:sx"usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression] find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]
Manpageよりfind ユーティリティは、 pathname に対してディレクトリ
ツリーを再帰的に下って、ツリー上の各ファイルについて
expression (後に示す``プライマリ''と``演算子'' から構
成されます) で指定された処理を実行します。
42.オプションの種類2.オプションの種類オプション 効果
E-regex および -iregex の後の正規表現を、基本正規表現(BRE)でなく拡張正規表現として解釈。regexp_flags に 0001 を立てる。
H直接指定された有効なシンボリックリンクを処理するときだけ、 リンク先をたどる。それ以外はたどらない。L、Pとは排他的。
L有効なシンボリックリンクをたどる。シンボリックリンクが無効なときはたどらない。H、Pとは排他的。
Pシンボリックリンクをまったくたどらない。デフォルトの動作。H、Lとは排他的。
Xxargs的に無効な文字(スペース、タブ、LF、バックスラッシュ、シングルクォート、ダブルクォート)を含むパスは警告を出して、処理しない。
d深さ優先探索を行う。かといってデフォルトが幅優先かというとそうでもなく、デフォルトは”深さ優先探索だけどディレクトリを先に処理する版”。
ffind が探索するファイル階層を指定する。引数を取る。が、-f自体書かなくても同じ。
s探索時に、ディレクトリ内のファイルをアルファベット順に取得する。
x探索開始ディレクトリと違うファイルシステムを探索しないようにする。
オプション 効果
E-regex および -iregex の後の正規表現を、基本正規表現(BRE)でなく拡張正規表現として解釈。regexp_flags に 0001 を立てる。
H直接指定された有効なシンボリックリンクを処理するときだけ、 リンク先をたどる。それ以外はたどらない。L、Pとは排他的。
L有効なシンボリックリンクをたどる。シンボリックリンクが無効なときはたどらない。H、Pとは排他的。
Pシンボリックリンクをまったくたどらない。デフォルトの動作。H、Lとは排他的。
Xxargs的に無効な文字(スペース、タブ、LF、バックスラッシュ、シングルクォート、ダブルクォート)を含むパスは警告を出して、処理しない。
d深さ優先探索を行う。かといってデフォルトが幅優先かというとそうでもなく、デフォルトは”深さ優先探索だけどディレクトリを先に処理する版”。
ffind が探索するファイル階層を指定する。引数を取る。が、-f自体書かなくても同じ。
s探索時に、ディレクトリ内のファイルをアルファベット順に取得する。
x探索開始ディレクトリと違うファイルシステムを探索しないようにする。
53.PLANの作成3.PLANの作成関数 find_formplan (find.c) PLAN * find_formplan(char *argv[])でPLAN(リスト)を作成
関数 find_formplan (find.c) PLAN * find_formplan(char *argv[])でPLAN(リスト)を作成
nextnext nextnext -print-exec-ok
-print-exec-ok
nextnext
PLAN *planPLAN *plan PLAN *tailPLAN *tail
・最後のPLAN(*tail)は必ず -print、-exec、-okのどれかになる (find.c L117辺り~)・print、exec、okが指定されていないとき 勝手に'('')'付きで -print が補われる・'('や')'も一つのPLANになる
・最後のPLAN(*tail)は必ず -print、-exec、-okのどれかになる (find.c L117辺り~)・print、exec、okが指定されていないとき 勝手に'('')'付きで -print が補われる・'('や')'も一つのPLANになる
64.(),!,orの処理4.(),!,orの処理作成したリストから()、!、orを処理する。まず()を取り除く(サブプラン化する)。
$ find . \( ! -newer hoge -or -user foo \) -print
作成したリストから()、!、orを処理する。まず()を取り除く(サブプラン化する)。
$ find . \( ! -newer hoge -or -user foo \) -print
exprexprnextnext
p_datap_data
-print-print nextnext
-newer hoge-newer hoge nextnext -user foo-user foo nextnext
-print-print nextnext
-newer hoge-newer hoge nextnext
-user foo-user foo nextnext
(( nextnext
)) nextnext()除外()除外
-or-or nextnext
-or-or nextnext
!! nextnext
!! nextnext
74.(),!,orの処理4.(),!,orの処理次に!の否定先をサブプランにする。次に!の否定先をサブプランにする。
exprexprnextnext
p_datap_data
-print-print nextnext
-newer hoge-newer hoge nextnext -user foo-user foo nextnext
!処理!処理
-or-or nextnext!! nextnext
exprexprnextnext
p_datap_data
-print-print nextnext
-newer hoge-newer hoge nextnext
-user foo-user foo nextnext-or-or nextnext
!!nextnext
p_datap_data
84.(),!,orの処理4.(),!,orの処理最後に-orを処理する。最後に-orを処理する。
-or処理-or処理
exprexprnextnext
p_datap_data
-print-print nextnext
-newer hoge-newer hoge nextnext
-user foo-user foo nextnext-or-or nextnext
!!nextnext
p_datap_data
exprexprnextnext
p_datap_data-print-print nextnext
-newer hoge-newer hoge nextnext
-user foo-user foo nextnext
-or-or
nextnext
!!nextnext
p_datap_datap_data[0]p_data[0]
p_data[1]p_data[1]
top related