{"id":3394,"date":"2011-10-08T12:42:20","date_gmt":"2011-10-08T04:42:20","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=3394"},"modified":"2011-10-08T15:33:45","modified_gmt":"2011-10-08T07:33:45","slug":"shell%e6%89%b9%e9%87%8f%e6%9b%bf%e6%8d%a2%e6%96%87%e4%bb%b6%e6%89%a9%e5%b1%95%e5%90%8d","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/3394","title":{"rendered":"shell\u6279\u91cf\u66ff\u6362\u6587\u4ef6\u6269\u5c55\u540d"},"content":{"rendered":"<p>\u65e9\u4e0a\u672c\u60f3\u5c06\u4e00\u4e9b\u7167\u7247\u4e0a\u4f20\u5230\u76f8\u518c\u4e2d\uff0c\u4f46\u662f\u7531\u4e8e\u6240\u6709\u7167\u7247\u7684\u6269\u5c55\u540d\u90fd\u662fJPG\u800c\u4e0d\u662f\u5c0f\u5199\u7684jpg\uff0c\u56e0\u6b64\u9020\u6210\u4e86\u201c\u683c\u5f0f\u4e0d\u6b63\u786e\u201d\u800c\u4e0d\u80fd\u4e0a\u4f20\u7167\u7247\u3002\u6b64\u523b\u5c31\u4ea7\u751f\u4e86\u8fd9\u6837\u4e00\u4e2a\u95ee\u9898\uff1a\u4f7f\u7528shell\u811a\u672c\u5982\u4f55\u6279\u91cf\u5c06\u6240\u6709\u6587\u4ef6\u7684\u6269\u5c55\u540dJPG\u90fd\u6539\u6210\u5c0f\u5199\u7684jpg\uff1f<\/p>\n<p>\u65e2\u7136\u8981\u6279\u91cf\u66ff\u6362\u6587\u4ef6\u540d\uff0c\u90a3\u4e48\u80af\u5b9a\u5f97\u7528\u4e00\u4e2afor\u5faa\u73af\u4f9d\u6b21\u904d\u5386\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u6bcf\u4e2a\u6587\u4ef6\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u6587\u4ef6\uff0c\u5047\u5982\u8be5\u6587\u4ef6\u7684\u540d\u79f0\u4e3aname.oldext\uff0c\u90a3\u4e48\u6211\u4eec\u5fc5\u987b\u539f\u59cb\u6587\u4ef6\u540d\u4e2d\u6316\u51faname\uff0c\u518d\u5c06\u5b83\u4e0e\u65b0\u7684\u6587\u4ef6\u6269\u5c55\u540dnewext\u62fc\u63a5\u5f62\u6210\u65b0\u7684\u6587\u4ef6\u540dname.newext\u3002\u4f9d\u7167\u8fd9\u6837\u7684\u601d\u8def\uff0c\u5c31\u8bde\u751f\u4e86\u4e0b\u9762\u7684\u811a\u672c\uff1a<\/p>\n<pre class=\"brush:bash\">#!\/bin\/bash\r\noldext=\"JPG\"\r\nnewext=\"jpg\"\r\n\r\ndir=\"\/home\/edsionte\/mypic\"\r\ncd $dir\r\n\r\nfor file in $(ls $dir | grep .$oldext)\r\n\r\n\tdo\r\n\tname=$(ls $file | cut -d. -f1)\r\n\tmv $file ${name}.$newext\r\n\tdone<\/pre>\n<p>\u4e0b\u9762\u5bf9\u9488\u5bf9\u8fd9\u4e2a\u7a0b\u5e8f\u4f5c\u7b80\u5355\u8bf4\u660e\uff1a<\/p>\n<p>1.\u53d8\u91cfoldext\u548cnewext\u5206\u522b\u6307\u5b9a\u65e7\u7684\u6269\u5c55\u540d\u548c\u65b0\u7684\u6269\u5c55\u540d\u3002dir\u6307\u5b9a\u6587\u4ef6\u6240\u5728\u76ee\u5f55\uff1b<\/p>\n<p>2.\u201cls $dir | grep .$oldext\u201d\u7528\u6765\u5728\u6307\u5b9a\u76ee\u5f55dir\u4e2d\u83b7\u53d6\u6269\u5c55\u540d\u4e3a\u65e7\u6269\u5c55\u540d\u7684\u6240\u6709\u6587\u4ef6\uff1b<\/p>\n<p>3.\u5728\u5faa\u73af\u4f53\u5185\u5148\u5229\u7528cut\u547d\u4ee4\u5c06\u6587\u4ef6\u540d\u4e2d\u201c.\u201d\u4e4b\u524d\u7684\u5b57\u7b26\u4e32\u526a\u5207\u51fa\u6765\uff0c\u5e76\u8d4b\u503c\u7ed9name\u53d8\u91cf\uff1b\u63a5\u7740\u5c06\u5f53\u524d\u7684\u6587\u4ef6\u540d\u91cd\u547d\u540d\u4e3a\u65b0\u7684\u6587\u4ef6\u540d\u3002<\/p>\n<p>\u901a\u8fc7\u8fd9\u4e2a\u811a\u672c\uff0c\u6240\u6709\u7167\u7247\u7684\u6269\u5c55\u540d\u90fd\u6210\u529f\u4fee\u6539\u3002\u4e3a\u4e86\u4f7f\u8fd9\u4e2a\u811a\u672c\u66f4\u5177\u6709\u901a\u7528\u578b\uff0c\u6211\u4eec\u53ef\u4ee5\u589e\u52a0\u51e0\u6761read\u547d\u4ee4\u5b9e\u73b0\u811a\u672c\u548c\u7528\u6237\u4e4b\u95f4\u7684\u4ea4\u4e92\u3002\u6539\u8fdb\u7248\u7684\u811a\u672c\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush:bash\">\r\n#!\/bin\/bash\r\n\r\nread -p \"old extension:\" oldext\r\nread -p \"new extension:\" newext\r\nread -p \"The directory:\" dir\r\ncd $dir\r\n\r\nfor file in $(ls $dir | grep .$oldext)\r\n\r\n\tdo\r\n\tname=$(ls $file | cut -d. -f1)\r\n\tmv $file ${name}.$newext\r\n\techo \"$name.$oldext ====> $name.$newext\"\r\n\tdone\r\necho \"all files has been modified.\"\r\n<\/pre>\n<p>\u4fee\u6539\u540e\u7684\u811a\u672c\u53ef\u4ee5\u6279\u91cf\u4fee\u6539\u4efb\u610f\u6269\u5c55\u540d\u3002done\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u65e9\u4e0a\u672c\u60f3\u5c06\u4e00\u4e9b\u7167\u7247\u4e0a\u4f20\u5230\u76f8\u518c\u4e2d\uff0c\u4f46\u662f\u7531\u4e8e\u6240\u6709\u7167\u7247\u7684\u6269\u5c55\u540d\u90fd\u662fJPG\u800c\u4e0d\u662f\u5c0f\u5199\u7684jpg\uff0c\u56e0\u6b64\u9020\u6210\u4e86\u201c\u683c\u5f0f\u4e0d\u6b63\u786e\u201d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[153],"tags":[263,155,262],"class_list":["post-3394","post","type-post","status-publish","format-standard","hentry","category-shell","tag-cut","tag-shell","tag-262"],"views":14185,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/3394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/comments?post=3394"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/3394\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=3394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=3394"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=3394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}