例えば、現在のフォルダの中のすべてのcgiの先頭行を
#!/usr/bin/perlから#!/usr/local/bin/perlに変更したい時
find ./ -name "*.cgi" -exec perl -i -pe 's|#!/usr/bin/perl|#!/usr/local/bin/perl|' {} \;
を、ターミナルから実行。
解説
find [dir name] ← UNIXコマンドの一。条件に合うファイルを指定したフォルダ以下から探す。
-name "[target name]"← 名前で検索しろよ、というoption。*はワイルドカードとして使用。
-exec [cmd] {}←見つかったファイルのパスを{}に代入してcmdの内容を実行しろ、というoption。
\; ← findここで終わり、の宣言。( \は;をshellではなくfindに渡すためのエスケープ文字)
で、
perl ← 実行するのはperlスクリプトですよ、って宣言。
-e ← perlを実行して処理が済んだらperlを終了しますよってoption。
-p ← 置換をファイルの先頭から最後までループでやるよっていうoption
-i ← 複数ファイル一括処理option。
's|[a]|[b]|' ← aという文字列をbに置換しろよ、という命令。
ということでした。
findのoption一覧
| 検索の条件-基本 | 機能 |
| -name [file name] | 指定した文字列のファイル・ディレクトリを検索 |
| -user [user name] | 指定したユーザーが所有するファイル・ディレクトリを検索 |
| -group [group name] | 指定したグループが所有するファイル・ディレクトリを検索 |
| -type [filetype] | ファイルの種類を指定して検索 |
| b:ブロック型特殊ファイル c:キャラクタ型特殊ファイル d:ディレクトリ l:シンボリックリンク f:通常ファイル | |
| 検索の条件-日時 | 機能 |
| -atime (+/-)n | 最後にアクセスしたのがn日前のファイル・ディレクトリを検索(+n:n日以上、-n:n日以下) |
| -ctime (+/-)n | 最後にステータスが修正されたのがn日前のファイル・ディレクトリを検索(+n:n日以上、-n:n日以下) |
| -mtime (+/-)n | 最後にデータが修正されたのがn日前のファイル・ディレクトリを検索(+n:n日以上、-n:n日以下) |
| -mmin (+/-)n | 最後にデータが修正されたのがn分前のファイル・ディレクトリを検索(+n:n分以上、-n:n分以下) |
| -newer [file name] | 指定したファイルよりも後に更新されているファイル・ディレクトリを検索 |
| 検索の条件-サイズ | 機能 |
| -size n[c/k/b] | nのサイズのファイルを検索(c:バイト、k:キロバイト、b:ブロック-1ブロック=512バイト) |
| 検索結果の処理 | 機能 |
| -ls | 詳細を一覧表示する |
| 検索結果の標準出力 | |
| -fprint [file name] | 検索結果を指定したファイルに書き出す |
| -exec [command] {} \; | 検索結果をコマンドに引き渡して実行 |
pealのoption一覧
-0[octal] specify record separator (\0, if no argument)
-a autosplit mode with -n or -p (splits $_ into @F)
-C[number/list] enables the listed Unicode features
-c check syntax only (runs BEGIN and CHECK blocks)
-d[:debugger] run program under debugger
-D[number/list] set debugging flags (argument is a bit mask or alphabets)
-e program one line of program (several -e's allowed, omit programfile)
-f don't do $sitelib/sitecustomize.pl at startup
-F/pattern/ split() pattern for -a switch (//'s are optional)
-i[extension] edit <> files in place (makes backup if extension supplied)
-Idirectory specify @INC/#include directory (several -I's allowed)
-l[octal] enable line ending processing, specifies line terminator
-[mM][-]module execute "use/no module..." before executing program
-n assume "while (<>) { ... }" loop around program
-p assume loop like -n but print line also, like sed
-P run program through C preprocessor before compilation
-s enable rudimentary parsing for switches after programfile
-S look for programfile using PATH environment variable
-t enable tainting warnings
-T enable tainting checks
-u dump core after parsing program
-U allow unsafe operations
-v print version, subversion (includes VERY IMPORTANT perl info)
-V[:variable] print configuration summary (or a single Config.pm variable)
-w enable many useful warnings (RECOMMENDED)
-W enable all warnings
-x[directory] strip off text before #!perl line and perhaps cd to directory
-X disable all warnings
0 件のコメント:
コメントを投稿