{"id":142850,"date":"2019-04-25T09:31:17","date_gmt":"2019-04-25T01:31:17","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=142850"},"modified":"2019-04-17T09:32:51","modified_gmt":"2019-04-17T01:32:51","slug":"commands-linux","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/commands-linux.html","title":{"rendered":"\u65b9\u62ec\u53f7\u53ca\u5176\u5728\u547d\u4ee4\u884c\u4e2d\u7684\u4e0d\u540c\u7528\u6cd5\u4ecb\u7ecd"},"content":{"rendered":"
\u901a\u914d<\/strong><\/div>\n

\u65b9\u62ec\u53f7\u6700\u7b80\u5355\u7684\u7528\u6cd5\u5c31\u662f\u901a\u914d\u3002\u4f60\u53ef\u80fd\u5728\u77e5\u9053\u201cGlobbing<\/rt><\/ruby>\u201d\u8fd9\u4e2a\u6982\u5ff5\u4e4b\u524d\u5c31\u5df2\u7ecf\u901a\u8fc7\u901a\u914d\u6765\u5339\u914d\u5185\u5bb9\u4e86\uff0c\u5217\u51fa\u5177\u6709\u76f8\u540c\u7279\u5f81\u7684\u591a\u4e2a\u6587\u4ef6\u5c31\u662f\u4e00\u4e2a\u5f88\u5e38\u89c1\u7684\u573a\u666f\uff0c\u4f8b\u5982\u5217\u51fa\u6240\u6709 JPEG \u6587\u4ef6\uff1a<\/p>\n

ls *.jpg<\/pre>\n

\u4f7f\u7528\u901a\u914d\u7b26wildcard\u6765\u5f97\u5230\u7b26\u5408\u67d0\u4e2a\u6a21\u5f0f\u7684\u6240\u6709\u5185\u5bb9\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u5c31\u53eb\u901a\u914d\u3002<\/p>\n

\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u5f53\u4e2d\uff0c\u661f\u53f7\uff08*\uff09\u5c31\u4ee3\u8868\u201c0 \u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u201d\u3002\u9664\u6b64\u4ee5\u5916\uff0c\u8fd8\u6709\u4ee3\u8868\u201c\u6709\u4e14\u4ec5\u6709\u4e00\u4e2a\u5b57\u7b26\u201d\u7684\u95ee\u53f7\uff08?\uff09\u3002\u56e0\u6b64<\/p>\n

ls d*k*<\/pre>\n

\u53ef\u4ee5\u5217\u51fa darkly \u548c ducky\uff0c\u800c\u4e14 dark \u548c duck \u4e5f\u662f\u53ef\u4ee5\u88ab\u5217\u51fa\u7684\uff0c\u56e0\u4e3a * \u53ef\u4ee5\u5339\u914d 0 \u4e2a\u5b57\u7b26\u3002\u800c<\/p>\n

ls d*k?<\/pre>\n

\u5219\u53ea\u80fd\u5217\u51fa ducky\uff0c\u4e0d\u4f1a\u5217\u51fa darkly\u3001dark \u548c duck\u3002<\/p>\n

\u65b9\u62ec\u53f7\u4e5f\u53ef\u4ee5\u7528\u4e8e\u901a\u914d\u3002\u4e3a\u4e86\u4fbf\u4e8e\u6f14\u793a\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u7528\u4e8e\u6d4b\u8bd5\u7684\u76ee\u5f55\uff0c\u5e76\u5728\u8fd9\u4e2a\u76ee\u5f55\u4e0b\u521b\u5efa\u6587\u4ef6\uff1a<\/p>\n

touch file0{0..9}{0..9}<\/pre>\n

\u6267\u884c\u4e0a\u9762\u8fd9\u4e2a\u547d\u4ee4\u4e4b\u540e\uff0c\u5c31\u4f1a\u521b\u5efa file000\u3001file001\u3001\u2026\u2026\u3001file099 \u8fd9 100 \u4e2a\u6587\u4ef6\u3002<\/p>\n

\u5982\u679c\u8981\u5217\u51fa\u8fd9\u4e9b\u6587\u4ef6\u5f53\u4e2d\u7b2c\u4e8c\u4f4d\u6570\u5b57\u662f 7 \u6216 8 \u7684\u6587\u4ef6\uff0c\u53ef\u4ee5\u6267\u884c\uff1a<\/p>\n

ls file0[78]?<\/pre>\n

\u5982\u679c\u8981\u5217\u51fa file022\u3001file027\u3001file028\u3001file052\u3001file057\u3001file058\u3001file092\u3001file097\u3001file098\uff0c\u53ef\u4ee5\u6267\u884c\uff1a<\/p>\n

ls file0[259][278]<\/pre>\n

\u5f53\u7136\uff0c\u4e0d\u4ec5\u4ec5\u662f ls\uff0c\u5f88\u591a\u5176\u5b83\u7684\u547d\u4ee4\u884c\u5de5\u5177\u90fd\u53ef\u4ee5\u4f7f\u7528\u65b9\u62ec\u53f7\u6765\u8fdb\u884c\u901a\u914d\u64cd\u4f5c\u3002\u4f46\u5728\u5220\u9664\u6587\u4ef6\u3001\u79fb\u52a8\u6587\u4ef6\u3001\u590d\u5236\u6587\u4ef6\u7684\u8fc7\u7a0b\u4e2d\u4f7f\u7528\u901a\u914d\uff0c\u4f60\u9700\u8981\u6709\u4e00\u70b9\u6a2a\u5411\u601d\u7ef4\u3002<\/p>\n

\u4f8b\u5982\u5c06 file010 \u5230 file029 \u8fd9 30 \u4e2a\u6587\u4ef6\u590d\u5236\u6210 archive010 \u5230 archive029 \u8fd9 30 \u4e2a\u526f\u672c\uff0c\u4e0d\u53ef\u4ee5\u8fd9\u6837\u6267\u884c\uff1a<\/p>\n

cp file0[12]? archive0[12]?<\/pre>\n

\u56e0\u4e3a\u901a\u914d\u53ea\u80fd\u9488\u5bf9\u5df2\u6709\u7684\u6587\u4ef6\uff0c\u800c archive \u5f00\u5934\u7684\u6587\u4ef6\u5e76\u4e0d\u5b58\u5728\uff0c\u4e0d\u80fd\u8fdb\u884c\u901a\u914d\u3002<\/p>\n

\u800c\u8fd9\u6761\u547d\u4ee4<\/p>\n

cp file0[12]? archive0[1..2][0..9]<\/pre>\n

\u4e5f\u540c\u6837\u4e0d\u884c\uff0c\u56e0\u4e3a cp\u00a0\u5e76\u4e0d\u5141\u8bb8\u5c06\u591a\u4e2a\u6587\u4ef6\u590d\u5236\u5230\u591a\u4e2a\u6587\u4ef6\u3002\u5728\u590d\u5236\u591a\u4e2a\u6587\u4ef6\u7684\u60c5\u51b5\u4e0b\uff0c\u53ea\u80fd\u5c06\u591a\u4e2a\u6587\u4ef6\u590d\u5236\u5230\u4e00\u4e2a\u6307\u5b9a\u7684\u76ee\u5f55\u4e0b\uff1a<\/p>\n

mkdir archive\r\ncp file0[12]? archive<\/pre>\n

\u8fd9\u6761\u547d\u4ee4\u662f\u53ef\u4ee5\u6b63\u5e38\u8fd0\u884c\u7684\uff0c\u4f46\u5b83\u53ea\u4f1a\u628a\u8fd9 30 \u4e2a\u6587\u4ef6\u4ee5\u540c\u6837\u7684\u540d\u79f0\u590d\u5236\u5230 archive\/ \u76ee\u5f55\u4e0b\uff0c\u800c\u8fd9\u5e76\u4e0d\u662f\u6211\u4eec\u60f3\u8981\u7684\u6548\u679c\u3002<\/p>\n

\u5982\u679c\u4f60\u9605\u8bfb\u8fc7\u6211\u5173\u4e8e\u82b1\u62ec\u53f7\u7684\u6587\u7ae0\uff0c\u4f60\u5927\u6982\u4f1a\u8bb0\u5f97\u53ef\u4ee5\u4f7f\u7528 % \u6765\u622a\u6389\u5b57\u7b26\u4e32\u7684\u672b\u5c3e\u90e8\u5206\uff0c\u800c\u4f7f\u7528 # \u5219\u53ef\u4ee5\u622a\u6389\u5b57\u7b26\u4e32\u7684\u5f00\u5934\u90e8\u5206\u3002<\/p>\n

\u4f8b\u5982\uff1a<\/p>\n

myvar=\"Hello World\"\r\necho Goodbye Cruel ${myvar#Hello}<\/pre>\n

\u5c31\u4f1a\u8f93\u51fa Goodbye Cruel World\uff0c\u56e0\u4e3a #Hello \u5c06 myvar \u53d8\u91cf\u4e2d\u5f00\u5934\u7684 Hello \u53bb\u6389\u4e86\u3002<\/p>\n

\u5728\u901a\u914d\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e00\u4e2a\u6280\u5de7\u3002<\/p>\n

for i in file0[12]?;\\\r\ndo\\\r\ncp $i archive${i#file};\\\r\ndone<\/pre>\n

\u4e0a\u9762\u7684\u7b2c\u4e00\u884c\u547d\u4ee4\u544a\u8bc9 Bash \u9700\u8981\u5bf9\u6240\u6709 file01 \u5f00\u5934\u6216\u8005 file02 \u5f00\u5934\uff0c\u4e14\u540e\u9762\u53ea\u8ddf\u4e00\u4e2a\u4efb\u610f\u5b57\u7b26\u7684\u6587\u4ef6\u8fdb\u884c\u64cd\u4f5c\uff0c\u7b2c\u4e8c\u884c\u7684 do \u548c\u7b2c\u56db\u884c\u7684 done \u4ee3\u8868\u9700\u8981\u5bf9\u8fd9\u4e9b\u6587\u4ef6\u90fd\u6267\u884c\u8fd9\u4e00\u5757\u4e2d\u7684\u547d\u4ee4\u3002<\/p>\n

\u7b2c\u4e09\u884c\u5c31\u662f\u5b9e\u9645\u7684\u590d\u5236\u64cd\u4f5c\u4e86\uff0c\u8fd9\u91cc\u4f7f\u7528\u4e86\u4e24\u6b21 $i \u53d8\u91cf\uff1a\u7b2c\u4e00\u6b21\u5728 cp \u547d\u4ee4\u4e2d\u76f4\u63a5\u4f5c\u4e3a\u6e90\u6587\u4ef6\u7684\u6587\u4ef6\u540d\u4f7f\u7528\uff0c\u7b2c\u4e8c\u6b21\u5219\u662f\u622a\u6389\u6587\u4ef6\u540d\u5f00\u5934\u7684 file \u90e8\u5206\uff0c\u7136\u540e\u5728\u5f00\u5934\u8865\u4e0a\u4e00\u4e2a archive\uff0c\u4e5f\u5c31\u662f\u8fd9\u6837\uff1a<\/p>\n

\"archive\" + \"file019\" - \"file\" = \"archive019\"<\/pre>\n

\u6700\u7ec8\u6574\u4e2a cp \u547d\u4ee4\u5c55\u5f00\u4e3a\uff1a<\/p>\n

cp file019 archive019<\/pre>\n

\u6700\u540e\uff0c\u987a\u5e26\u8bf4\u660e\u4e00\u4e0b\u53cd\u659c\u6760 \\ \u7684\u4f5c\u7528\u662f\u5c06\u4e00\u6761\u957f\u547d\u4ee4\u62c6\u5206\u6210\u591a\u884c\uff0c\u8fd9\u6837\u53ef\u4ee5\u65b9\u4fbf\u9605\u8bfb\u3002<\/p>\n

\u5728\u4e0b\u4e00\u8282\uff0c\u6211\u4eec\u4f1a\u4e86\u89e3\u65b9\u62ec\u53f7\u7684\u66f4\u591a\u7528\u6cd5\uff0c\u656c\u8bf7\u5173\u6ce8\u3002<\/p>\n


\n

via: https:\/\/www.linux.com\/blog\/2019\/3\/using-square-brackets-bash-part-1<\/a><\/p>\n

\u4f5c\u8005\uff1aPaul Brown<\/a> \u9009\u9898\uff1alujun9972<\/a> \u8bd1\u8005\uff1aHankChow<\/a> \u6821\u5bf9\uff1awxy<\/a><\/p>\n

\u672c\u6587\u7531 LCTT<\/a> \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd<\/a> \u8363\u8a89\u63a8\u51fa<\/p>\n","protected":false},"excerpt":{"rendered":"

\u65b9\u62ec\u53f7\u6700\u7b80\u5355\u7684\u7528\u6cd5\u5c31\u662f\u901a\u914d\u3002\u4f60\u53ef\u80fd\u5728\u77e5\u9053\u201cGlobbing\u201d\u8fd9\u4e2a\u6982\u5ff5\u4e4b\u524d\u5c31\u5df2\u7ecf\u901a\u8fc7\u901a\u914d\u6765\u5339\u914d\u5185\u5bb9\u4e86\uff0c\u5217\u51fa\u5177\u6709\u76f8 […]<\/p>\n","protected":false},"author":323,"featured_media":104099,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-142850","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/142850","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/323"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=142850"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/142850\/revisions"}],"predecessor-version":[{"id":143148,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/142850\/revisions\/143148"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/104099"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=142850"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=142850"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=142850"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}