{"id":314,"date":"2013-10-26T20:06:45","date_gmt":"2013-10-26T11:06:45","guid":{"rendered":"http:\/\/www.chihayafuru.jp\/tech\/?p=314"},"modified":"2024-05-15T08:57:57","modified_gmt":"2024-05-14T23:57:57","slug":"tips-find%e3%82%b3%e3%83%9e%e3%83%b3%e3%83%89","status":"publish","type":"post","link":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/archives\/314","title":{"rendered":"find\u30b3\u30de\u30f3\u30c9\u306e\u4f7f\u3044\u65b9"},"content":{"rendered":"<h2>\u30d5\u30a9\u30eb\u30c0\u540d\u3084\u30d5\u30a1\u30a4\u30eb\u540d\u306b\u542b\u307e\u308c\u308b\u30b9\u30da\u30fc\u30b9\u6587\u5b57\u3092\u56de\u907f\u3059\u308b<\/h2>\n<h3>\u4f8b<\/h3>\n<pre class=\"lang:sh decode:true \" >$ find . -name '*.c' -print0 | xargs -0 grep 'pattern'<\/pre>\n<h3>\u8aac\u660e<\/h3>\n<p>\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u533a\u5207\u308a\u6587\u5b57\u306f\u30b9\u30da\u30fc\u30b9\u6587\u5b57\u3002-print0 \u6307\u5b9a\u3067\u533a\u5207\u308a\u6587\u5b57\u3092NUL\u6587\u5b57\u306b\u5909\u66f4\u3059\u308b\u3002xargs\u306e\u533a\u5207\u308a\u6587\u5b57\u6307\u5b9a\u3092\u3042\u308f\u305b\u3066NUL\u6587\u5b57\u306b\u3059\u308b\u3053\u3068\u3067\u3001\u30d5\u30a9\u30eb\u30c0\u540d\u3084\u30d5\u30a1\u30a4\u30eb\u540d\u306b\u542b\u307e\u308c\u3066\u3044\u308b\u30b9\u30da\u30fc\u30b9\u6587\u5b57\u3092\u533a\u5207\u308a\u6587\u5b57\u3068\u8aa4\u8a8d\u3059\u308b\u3053\u3068\u3092\u56de\u907f\u3059\u308b\u3002<\/p>\n<p><!--more--><br \/>\n<\/p>\n<hr>\n<p><\/p>\n<h2>\u691c\u7d22\u30d5\u30a1\u30a4\u30eb\u540d\u3092 xargs \u3067\u53d7\u3051\u53d6\u308a\u3001\u30d1\u30a4\u30d7\u30e9\u30a4\u30f3\u5f8c\u306e\u30b3\u30de\u30f3\u30c9\u306b\u6e21\u3059<\/h2>\n<pre class=\"lang:sh decode:true \" >$ find . -type f -name '*.jpg' -print0 | xargs -0 -J % cp % ~\/img\/<\/pre>\n<ul>\n<li><code>-J<\/code> \u3067\u7f6e\u63db\u6587\u5b57\u3092\u6307\u5b9a\u3059\u308b\u3002&quot;%&quot; \u304c\u30d5\u30a1\u30a4\u30eb\u540d\u306b\u7f6e\u304d\u63db\u3048\u3089\u308c\u308b\u3002<\/li>\n<\/ul>\n<h2>\u691c\u7d22\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u5f15\u6570\u306b\u3057\u3066 exec \u3067\u5b9f\u884c\u3059\u308b\u3002<\/h2>\n<pre class=\"lang:sh decode:true \" >$ find . -type f -name '*.jpg' -exec cp {} ~\/img\/ \\;<\/pre>\n<ul>\n<li><code>{}<\/code> : \u30d5\u30a1\u30a4\u30eb\u540d\u306b\u7f6e\u304d\u63db\u3048\u308b\u3089\u308c\u308b\u3002<\/li>\n<li>\n    <code>\\;<\/code> : \u5358\u4f53\u5b9f\u884c\u3002cp\u30b3\u30de\u30f3\u30c9\u3092\u30d5\u30a1\u30a4\u30eb\u540d\u6bce\u306b1\u56de1\u56de\u5b9f\u884c\u3059\u308b\u3002<\/p>\n<ul>\n<li><code> cp foo.jpg ~\/img\/<\/code><\/li>\n<li><code> cp bar.jpg ~\/img\/<\/code><\/li>\n<li><code> cp baz.jpg ~\/img\/<\/code><\/li>\n<li>&#8230;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><\/p>\n<hr>\n<p><\/p>\n<h2>\u30a2\u30af\u30bb\u30b9\u5236\u9650\u306e\u30a8\u30e9\u30fc\u3092\u8868\u793a\u3055\u305b\u306a\u3044\u3002<\/h2>\n<h3>\u5931\u6557\u4f8b<\/h3>\n<pre class=\"lang:sh decode:true \" >% find . -name '*.asta'\r\nfind: .\/Pictures\/\u5199\u771f\u30e9\u30a4\u30d6\u30e9\u30ea.photoslibrary: Operation not permitted\r\nfind: .\/Desktop: Operation not permitted\r\n...<\/pre>\n<h3>\u89e3\u6c7a\u6cd5 : \u6a19\u6e96\u30a8\u30e9\u30fc\u51fa\u529b\u3092null\u30c7\u30d0\u30a4\u30b9\u3078\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3059\u308b\u3002<\/h3>\n<pre class=\"lang:sh decode:true \" >% find . -name '*.asta' 2>\/dev\/null<\/pre>\n<p><\/p>\n<hr>\n<p><\/p>\n<h2>\u30d5\u30a1\u30a4\u30eb\u540d\u3084\u30d5\u30a9\u30eb\u30c0\u540d\u306e\u5927\u6587\u5b57\uff0f\u5c0f\u6587\u5b57\u3092\u533a\u5225\u3057\u306a\u3044<\/h2>\n<h3>\u4f8b<\/h3>\n<pre class=\"lang:sh decode:true \" >$ find . -iname '*.c'<\/pre>\n<h3>\u8aac\u660e<\/h3>\n<p>-iname\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067 &quot;foo.c&quot; \u3068 &quot;foo.C&quot; \u306e\u4e21\u65b9\u304c\u691c\u7d22\u3055\u308c\u308b\u3002<\/p>\n<p><\/p>\n<hr>\n<p><\/p>\n<h2>\u8907\u6570\u6761\u4ef6\u3092\u6307\u5b9a\u3059\u308b<\/h2>\n<h3>\u4f8b<\/h3>\n<pre class=\"lang:sh decode:true \" >$ find . \\( -name '*.c' -o -name '*.h' \\)<\/pre>\n<h3>\u8aac\u660e<\/h3>\n<p>-o \u307e\u305f\u306f -or \u3067\u8907\u6570\u306e\u6761\u4ef6\u3092\u62ec\u5f27\u3067\u62ec\u3063\u3066\u9023\u7d50\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/p>\n<p><\/p>\n<hr>\n<p><\/p>\n<h2>\u30d5\u30a1\u30a4\u30eb\u306e\u307f\u3092\u691c\u7d22\u5bfe\u8c61\u3068\u3059\u308b<\/h2>\n<h3>\u4f8b<\/h3>\n<pre class=\"lang:sh decode:true \" >$ find . -type f -name 'project.*'<\/pre>\n<ul>\n<li><code>f<\/code> : \u30d5\u30a1\u30a4\u30eb<\/li>\n<li><code>d<\/code> : \u30c7\u30a3\u30ec\u30af\u30c8\u30ea<\/li>\n<\/ul>\n<p><\/p>\n<hr>\n<p><\/p>\n<h2>\u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u3067\u691c\u7d22\u3059\u308b<\/h2>\n<h3>\u4f8b. \uff13\uff10\u65e5\u4ee5\u524d\u306b\u66f4\u65b0\u3055\u308c\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u691c\u7d22<\/h3>\n<pre class=\"lang:sh decode:true \" >$ find . -ctime -30 -type f<\/pre>\n<h3>\u4f8b. \uff13\uff10\u65e5\u4ee5\u964d\u306b\u66f4\u65b0\u3055\u308c\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u691c\u7d22<\/h3>\n<pre class=\"lang:sh decode:true \" >$ find . -ctime +30 -type f<\/pre>\n<p><\/p>\n<hr>\n<p><\/p>\n<h2>\u7279\u5b9a\u306e\u30d5\u30a9\u30eb\u30c0\u3092\u9664\u5916\u3057\u3066\u30d5\u30a1\u30a4\u30eb\u4e00\u89a7\u3092\u4f5c\u6210\u3059\u308b<\/h2>\n<pre class=\"lang:sh decode:true \" >$ find . -type d -name '.git' -prune -o -type f -print<\/pre>\n<h3>\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u610f\u5473\u3092\u308f\u304b\u308a\u3084\u3059\u304f\u3059\u308b\u305f\u3081\u306b\u62ec\u5f27\u3067\u62ec\u3063\u305f\u4f8b<\/h3>\n<pre class=\"lang:sh decode:true \" >$ find . \\( -type d -and -name '.git' -and -prune \\) -or \\( -type f -and -print \\)<\/pre>\n<p>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea &quot;.git&quot; \u3092\u9664\u5916(prune) \u3057\u3001\u30d5\u30a1\u30a4\u30eb\u3092\u30d7\u30ea\u30f3\u30c8\u3059\u308b<\/p>\n<p><\/p>\n<hr>\n<p><\/p>\n<h3>\u5185\u90e8\u30ea\u30f3\u30af<\/h3>\n<ul>\n<li><a href=\"\/tech\/index.php\/archives\/4758\">find\u30b3\u30de\u30f3\u30c9 -exec \u30aa\u30d7\u30b7\u30e7\u30f3<\/a><\/li>\n<li><a href=\"\/tech\/index.php\/archives\/3316\">find\u30b3\u30de\u30f3\u30c9\u3067\u7279\u5b9a\u306e\u30d5\u30a9\u30eb\u30c0\u3092\u9664\u5916\u3059\u308b<\/a><\/li>\n<li><a href=\"\/tech\/index.php\/archives\/3793\">\u6587\u5b57\u30a8\u30f3\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u306b\u3088\u308b\u30d5\u30a1\u30a4\u30eb\u691c\u7d22<\/a><\/li>\n<li><a href=\"\/tech\/index.php\/archives\/3411\">\u7a7a\u306e\u30d5\u30a9\u30eb\u30c0\u3092\u691c\u7d22\u3059\u308b<\/a><\/li>\n<li><a href=\"\/tech\/index.php\/archives\/6555\">\u30b5\u30a4\u30ba\u30bc\u30ed\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u524a\u9664\u3059\u308b<\/a><\/li>\n<\/ul>\n<h3>\u5916\u90e8\u30ea\u30f3\u30af<\/h3>\n<ul>\n<li><a href=\"https:\/\/qiita.com\/ko1nksm\/items\/9ff1f212255e8520070c\">POSIX \u6e96\u62e0\u306e\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u306f find | xargs \u3088\u308a\u3082 find -exec {} + \u3092\u4f7f\u3046\u3079\u304d\uff01<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u30d5\u30a9\u30eb\u30c0\u540d\u3084\u30d5\u30a1\u30a4\u30eb\u540d\u306b\u542b\u307e\u308c\u308b\u30b9\u30da\u30fc\u30b9\u6587\u5b57\u3092\u56de\u907f\u3059\u308b \u4f8b $ find . -name &#8216;*.c&#8217; -print0 | xargs -0 grep &#8216;pattern&#8217; \u8aac\u660e \u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u533a\u5207\u308a\u6587\u5b57\u306f\u30b9\u30da\u30fc\u30b9\u6587\u5b57\u3002-pr [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-314","post","type-post","status-publish","format-standard","hentry","category-memo"],"_links":{"self":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts\/314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/comments?post=314"}],"version-history":[{"count":31,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts\/314\/revisions"}],"predecessor-version":[{"id":6793,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts\/314\/revisions\/6793"}],"wp:attachment":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/media?parent=314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/categories?post=314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/tags?post=314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}