{"id":5848,"date":"2025-01-12T07:29:00","date_gmt":"2025-01-11T23:29:00","guid":{"rendered":"https:\/\/ixyzero.com\/blog\/?p=5848"},"modified":"2025-01-10T16:31:51","modified_gmt":"2025-01-10T08:31:51","slug":"%e7%b1%bbunix%e7%b3%bb%e7%bb%9f%e4%b8%8a%e5%a6%82%e4%bd%95%e5%bf%ab%e9%80%9f%e6%89%b9%e9%87%8f%e9%87%8d%e5%91%bd%e5%90%8d%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/5848.html","title":{"rendered":"\u7c7bunix\u7cfb\u7edf\u4e0a\u5982\u4f55\u5feb\u901f\u6279\u91cf\u91cd\u547d\u540d\u6587\u4ef6"},"content":{"rendered":"\n<p>=Start=<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u7f18\u7531\uff1a<\/h4>\n\n\n\n<p>\u4e2d\u6587\u73af\u5883\u7684macOS\u7cfb\u7edf\u4e0a\u81ea\u52a8\u751f\u6210\u7684\u4e00\u4e9b\u6587\u4ef6\u6709\u4e0d\u5c11\u6587\u4ef6\u540d\u662f\u5305\u542b\u7a7a\u683c\u7684\uff0c\u5bf9\u4e8e\u7ec8\u7aef\u64cd\u4f5c\u4e0d\u662f\u592a\u65b9\u4fbf\uff0c\u6240\u4ee5\u9700\u8981\u5c06\u6587\u4ef6\u540d\u4e2d\u7684\u7a7a\u683c\u6279\u91cf\u66ff\u6362\u6210\u4e0b\u5212\u7ebf\u65b9\u4fbf\u540e\u9762\u7684\u5904\u7406\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\u5c31\u662f\u4e0d\u5f97\u4e0d\u611f\u6982\u4e00\u4e0b\u2014\u2014<mark style=\"background-color:rgba(0, 0, 0, 0);color:#ff0000\" class=\"has-inline-color\"><strong>\u5927\u6a21\u578b\u53ef\u80fd\u662f\u4f60\u80fd\u5feb\u901f\u76f4\u63a5\u63a5\u89e6\u5230\u7684\u6700\u535a\u5b66\u7684\u670b\u53cb\u4e86<\/strong>\uff0c<strong>\u5982\u679c\u662f\u73b0\u5b9e\u5df2\u6709\u89e3\u51b3\u65b9\u6cd5\u7684\u8bdd\uff0c\u4f60\u53ea\u8981\u901a\u8fc7\u5408\u9002\u7684prompt\u63d0\u793a\u8bcd\u5411\u4ed6\u63d0\u95ee\uff0c\u4ed6\u5927\u6982\u7387\u662f\u80fd\u5e2e\u4f60\u627e\u5230\u4e00\u4e9b\u65b9\u6cd5\u6216\u601d\u8def\u7684<\/strong>\uff0c\u6240\u4ee5\u4f60\u8981\u5229\u7528\u597d\u8fd9\u4e2a\u5de5\u5177\u53bb\u6269\u5c55\u81ea\u5df1\u7684\u80fd\u529b\u5708<\/mark>\uff0c\u4f46\u5728\u8fc7\u53bb\uff0c\u90a3\u4e9b\u5185\u5bb9\u4f60\u8fc7\u53bb\u5982\u679c\u6ca1\u6709\u5b9e\u9645\u505a\u8fc7\uff0c\u4f60\u662f\u5f88\u96be\u60f3\u5230\u7684\uff08\u5e38\u89c4\u7684\u641c\u7d22\u5f15\u64ce\u80fd\u68c0\u7d22\u5230\u7684\u5185\u5bb9\u548c\u6548\u679c\u4e5f\u975e\u5e38\u6709\u9650\uff09\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u6b63\u6587\uff1a<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">\u53c2\u8003\u89e3\u7b54\uff1a<\/h5>\n\n\n\n<p>\u5bf9\u5f53\u524d\u76ee\u5f55\u548c\u5b50\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u8fdb\u884c\u5904\u7406<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># vim ~\/.zshrc\nrename1() {\nfor file in *' '*; do &#91; -f \"$file\" ] &amp;&amp; mv \"$file\" \"${file\/\/ \/_}\"; done\n}\n\nrename22() {\nfind . -depth -name '* *' -execdir bash -c 'for f; do mv \"$f\" \"${f\/\/ \/_}\"; done' bash {} +\n# \u5339\u914d\u6587\u4ef6\u540d\u4e2d\u6709\u7a7a\u683c\u7684\u6587\u4ef6\u5217\u8868\uff0c\u7136\u540e\u5bf9\u5176\u4e2d\u7684\u6bcf\u4e00\u9879\u6267\u884c\u540e\u9762\u6307\u5b9a\u7684\u547d\u4ee4\n}\n\n# source ~\/.zshrc\n\n# \u5bf9\u5f53\u524d\u76ee\u5f55\u4e0b\u6587\u4ef6\u540d\u5305\u542b\u7a7a\u683c\u7684\u6587\u4ef6\u8fdb\u884c\u91cd\u547d\u540d\uff0c\u5bf9\u6587\u4ef6\u540d\u4e2d\u7684\u7a7a\u683c\u7528\u4e0b\u5212\u7ebf\u8fdb\u884c\u66ff\u6362\u3002\u4f7f\u7528\u7684\u65f6\u5019\u8981\u5207\u6362\u5230\u5bf9\u5e94\u76ee\u5f55\u4e0b\u6267\u884c\u8be5\u547d\u4ee4\u3002\nrename1<\/code><\/pre>\n\n\n\n<p>\u5bf9\u5f53\u524d\u76ee\u5f55\u53ca\u5176\u5b50\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u8fdb\u884c\u5904\u7406\uff08\u6d4b\u8bd5OK\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rename22() {\nfind . -depth -name '* *' -execdir bash -c 'for f; do mv \"$f\" \"${f\/\/ \/_}\"; done' bash {} +\n# \u5339\u914d\u6587\u4ef6\u540d\u4e2d\u6709\u7a7a\u683c\u7684\u6587\u4ef6\u5217\u8868\uff0c\u7136\u540e\u5bf9\u5176\u4e2d\u7684\u6bcf\u4e00\u9879\u6267\u884c\u540e\u9762\u6307\u5b9a\u7684\u547d\u4ee4\n}\n\n\n#\u501f\u52a9find\u547d\u4ee4\u7684\u9009\u9879\u63a7\u5236\u8fdb\u5165\u5b50\u76ee\u5f55\u7684\u6df1\u5ea6\nfind . -iname '* *'.png -maxdepth 1 -type f -print0 | while IFS= read -r -d $'\\0' fp; do\n    mv \"$fp\" \"${fp\/\/ \/_}\"\n\n    #\u4e0a\u97621\u884c\u5185\u5bb9\u6548\u679c\u7b49\u4ef7\u4e8e\u4e0b\u9762\u7684\u8fd9\u4e9b\u9664\u4e86echo\u6253\u5370\u529f\u80fd\u4e4b\u5916\u7684\u5185\u5bb9\n    echo \"$fp\"\n\n    newname=$(echo \"$fp\" | tr ' ' '_')\n    echo \"$newname\"\n    # \u4e0a\u97622\u884c\u4e5f\u53ef\u4ee5\u7528\u4e0b\u9762\u8fd9\u4e00\u884c\u6765\u66ff\u6362\n    echo \"${fp\/\/ \/_}\"\n\n    # mv \"$fp\" \"$newname\"\ndone<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>$ man find\n...\n-execdir utility &#91;argument ...] ;\n    The -execdir primary is identical to the -exec primary with the exception that utility will be executed from the directory that holds the current file.  The filename substituted for the string \u201c{}\u201d is not qualified.\n    -execdir primary\u4e0e-exec primary\u76f8\u540c\uff0c\u4e0d\u540c\u4e4b\u5904\u5728\u4e8e\u5b9e\u7528\u7a0b\u5e8f\u5c06\u4ece\u4fdd\u5b58\u5f53\u524d\u6587\u4ef6\u7684\u76ee\u5f55\u6267\u884c\u3002\u8fd9\u91cc\uff08\u4ee5\u82f1\u6587\u5206\u53f7\u7ed3\u5c3e\uff09\u4e0d\u652f\u6301\u66ff\u6362\u5b57\u7b26\u4e32\u201c{}\u201d\u7684\u6587\u4ef6\u540d\u3002\n\n-execdir utility &#91;argument ...] {} +\n    Same as -execdir, except that \u201c{}\u201d is replaced with as many pathnames as possible for each invocation of utility.  This behaviour is similar to that of xargs(1).  The primary always returns true; if at least one invocation of utility returns a non-zero exit status, find will return a non-zero exit status.\n    \u4e0e-execdir\u76f8\u540c\uff0c\u9664\u4e86\u6bcf\u6b21\u8c03\u7528\u5b9e\u7528\u7a0b\u5e8f\u65f6\u201c{}\u201d\u88ab\u66ff\u6362\u4e3a\u5c3d\u53ef\u80fd\u591a\u7684\u8def\u5f84\u540d\u3002\u8fd9\u79cd\u884c\u4e3a\u7c7b\u4f3c\u4e8exargs(1)\u3002\u521d\u7ea7\u51fd\u6570\u603b\u662f\u8fd4\u56detrue\uff1b\u5982\u679c\u81f3\u5c11\u6709\u4e00\u6b21\u8c03\u7528utility\u8fd4\u56de\u975e\u96f6\u9000\u51fa\u72b6\u6001\uff0cfind\u5c06\u8fd4\u56de\u975e\u96f6\u9000\u51fa\u72b6\u6001\u3002\n...<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">\u53c2\u8003\u94fe\u63a5\uff1a<\/h5>\n\n\n\n<p>\u901a\u4e49\u5343\u95ee<br><a href=\"https:\/\/tongyi.aliyun.com\/qianwen\/\">https:\/\/tongyi.aliyun.com\/qianwen\/<\/a><\/p>\n\n\n\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u4e2d\u6587\u73af\u5883\u7684macOS\u7cfb\u7edf\u4e0a\u81ea\u52a8\u751f\u6210\u7684\u4e00\u4e9b\u6587\u4ef6\u6709\u4e0d\u5c11\u6587\u4ef6\u540d\u662f\u5305\u542b\u7a7a\u683c\u7684\uff0c\u5bf9\u4e8e\u7ec8\u7aef\u64cd\u4f5c\u4e0d\u662f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,11,560],"tags":[2426,2427,83,89,485,30,1780,2428],"class_list":["post-5848","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","category-mac","tag-bashrc-2","tag-zshrc","tag-bash","tag-find","tag-ifs","tag-linux","tag-macos","tag-2428"],"views":1181,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/5848","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=5848"}],"version-history":[{"count":1,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/5848\/revisions"}],"predecessor-version":[{"id":5849,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/5848\/revisions\/5849"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=5848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=5848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=5848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}