サーバーのよく使うコマンドメモ| find

2015年2月11日

コマンド サーバー テクノロジー

Summery

ファイルの検索を行う。 xargsと組み合わせると、ファイル名の一括置換や、特定ファイルに対してのバッチ処理などが、柔軟に行える。

Construction

$ fond [option] [path] [expression]

Option

-type : [d ディレクトリ, f ファイル, l シンボリックリンク] -name : パターン -atime: 最後にアクセスしたn日前を対象に検索する

Sample

# /var/www/内にある".js"ファイルだけを抽出する $ find /var/www -name "*.js"

Discription

The find utility recursively descends the directory tree for each path listed, evaluat- ing an expression (composed of the ``primaries'' and ``operands'' listed below) in terms of each file in the tree. The options are as follows: -E Interpret regular expressions followed by -regex and -iregex primaries as extended (modern) regular expressions rather than basic regular expressions (BRE's). The re_format(7) manual page fully describes both formats. -H Cause the file information and file type (see stat(2)) returned for each sym- bolic link specified on the command line to be those of the file referenced by the link, not the link itself. If the referenced file does not exist, the file information and type will be for the link itself. File information of all sym- bolic links not on the command line is that of the link itself. -L Cause the file information and file type (see stat(2)) returned for each sym- bolic link to be those of the file referenced by the link, not the link itself. If the referenced file does not exist, the file information and type will be for the link itself. This option is equivalent to the deprecated -follow primary. -P Cause the file information and file type (see stat(2)) returned for each sym- bolic link to be those of the link itself. This is the default. -X Permit find to be safely used in conjunction with xargs(1). If a file name con- tains any of the delimiting characters used by xargs(1), a diagnostic message is displayed on standard error, and the file is skipped. The delimiting characters include single (`` ' '') and double (`` " '') quotes, backslash (``\''), space, tab and newline characters. However, you may wish to consider the -print0 primary in conjunction with ``xargs -0'' as an effective alternative. -d Cause find to perform a depth-first traversal, i.e., directories are visited in post-order and all entries in a directory will be acted on before the directory itself. By default, find visits directories in pre-order, i.e., before their contents. Note, the default is not a breadth-first traversal. This option is equivalent to the -depth primary of IEEE Std 1003.1-2001 (``POSIX.1''). The -d option can be useful when find is used with cpio(1) to process files that are contained in directories with unusual permissions. It ensures that you have write permission while you are placing files in a direc- tory, then sets the directory's permissions as the last thing. -f Specify a file hierarchy for find to traverse. File hierarchies may also be specified as the operands immediately following the options. -s Cause find to traverse the file hierarchies in lexicographical order, i.e., alphabetical order within each directory. Note: `find -s' and `find | sort' may give different results. -x Prevent find from descending into directories that have a device number differ- ent than that of the file from which the descent began. This option is equivalent to the deprecated -xdev primary.

このブログを検索

ごあいさつ

このWebサイトは、独自思考で我が道を行くユゲタの少し尖った思考のTechブログです。 毎日興味がどんどん切り替わるので、テーマはマルチになっています。 もしかしたらアイデアに困っている人の助けになるかもしれません。