{"id":157105,"date":"2019-08-31T09:05:52","date_gmt":"2019-08-31T01:05:52","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=157105"},"modified":"2019-08-27T10:07:17","modified_gmt":"2019-08-27T02:07:17","slug":"command-line-file-type-trick","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/command-line-file-type-trick.html","title":{"rendered":"\u547d\u4ee4\u884c\u5904\u7406\u6587\u4ef6\u6280\u5de7"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u6211\u4eec\u77e5\u9053\uff0c\u5c06\u67d0\u4e2a\u7c7b\u578b\u7684\u591a\u4e2a\u6587\u4ef6\u4ece\u4e00\u4e2a\u76ee\u5f55\u79fb\u52a8\u5230\u53e6\u4e00\u4e2a\u76ee\u5f55\u5f88\u7b80\u5355\uff0c\u4f46\u540c\u65f6\u79fb\u52a8\u591a\u79cd\u7c7b\u578b\u7684\u591a\u4e2a\u6587\u4ef6\u6216\u8bb8\u4f1a\u5f88\u9ebb\u70e6\uff0c\u8fd9\u91cc\u4ecb\u7ecd\u4e00\u4e9b\u8ba9\u4f60\u5728 Linux \u4e2d\u79fb\u52a8\u591a\u79cd\u6587\u4ef6\u7c7b\u578b\u7684\u5c0f\u6280\u5de7\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u65b9\u6cd51\uff1a<\/strong><\/div>\n

\u5047\u8bbe dir1 \u7684\u76ee\u5f55\u4e2d\u6709\u591a\u79cd\u7c7b\u578b\u7684\u6587\u4ef6\uff0c\u5982 .pdf .doc .mp3 .mp4 .txt \u7b49\uff0c\u6211\u4eec\u5148\u6765\u67e5\u770b dir1 \u4e2d\u7684\u5185\u5bb9\uff1a<\/p>\n

$ ls dir1 \r\nfile.txt image.jpg mydoc.doc personal.pdf song.mp3 video.mp4 \r\n<\/pre>\n

\u8fd9\u65f6\uff0c\u4f60\u5e0c\u671b\u5c06\u67d0\u4e9b\u6587\u4ef6\u7c7b\u578b(\u4e0d\u662f\u6240\u6709\u6587\u4ef6\u7c7b\u578b)\u79fb\u52a8\u5230\u4e0d\u540c\u7684\u4f4d\u7f6e\u3002\u4f8b\u5982\uff0c\u4f60\u60f3\u5c06 doc\uff0cpdf \u548c txt \u6587\u4ef6\u4e00\u6b21\u6027\u79fb\u52a8\u5230\u53e6\u4e00\u4e2a\u540d\u4e3a dir2 \u7684\u76ee\u5f55\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n

$ mv dir1\/*.{doc,pdf,txt} dir2\/ \r\n<\/pre>\n

\u7136\u540e\uff0c\u6211\u4eec\u5206\u522b\u67e5\u770b\u4e00\u4e0b dir1 \u548c dir2 \u76ee\u5f55\u4e2d\u7684\u5185\u5bb9\uff0c\u770b\u770b\u662f\u5426\u79fb\u52a8\u8fc7\u6765\u4e86\uff1a<\/p>\n

$ ls dir1\/ \r\nsong.mp3 video.mp4 \r\n$ ls dir2\/ \r\nfile.txt mydoc.doc personal.pdf \r\n<\/pre>\n

\u53ef\u4ee5\u770b\u51fa\u6765\uff0cdir1 \u4e2d\u7684 .doc .pdf \u548c .txt \u7c7b\u578b\u7684\u6587\u4ef6\u786e\u5b9e\u88ab\u79fb\u52a8\u5230\u4e86 dir2 \u3002\u4e0a\u9762\u547d\u4ee4\u4e2d\u7684\u82b1\u62ec\u53f7\u5185\u53ef\u4ee5\u6dfb\u52a0\u4efb\u610f\u6587\u4ef6\u7c7b\u578b\uff0c\u6765\u5c06\u5b83\u4eec\u79fb\u52a8\u5230\u53e6\u4e00\u4e2a\u76ee\u5f55\u4e2d\u3002\u600e\u4e48\u6837\uff0c\u662f\u4e0d\u662f\u5f88\u7b80\u5355?<\/p>\n

\u65b9\u6cd52\uff1a<\/strong><\/div>\n

\u6211\u4eec\u5148\u5207\u6362\u5230\u6e90\u76ee\u5f55\uff0c\u6211\u4eec\u8fd9\u91cc\u662f dir1 \uff1a<\/p>\n

$ cd ~\/dir1 \r\n<\/pre>\n

\u7136\u540e\u5c06\u9009\u62e9\u7684\u6587\u4ef6\u7c7b\u578b\u79fb\u52a8\u5230\u76ee\u6807\u76ee\u5f55 dir2 \uff1a<\/p>\n

$ mv *.doc *.txt *.pdf \/home\/alvin\/dir2\/ \r\n<\/pre>\n

\u82e5\u8981\u79fb\u52a8\u7279\u5b9a\u6269\u5c55\u540d\u7684\u6240\u6709\u6587\u4ef6\uff0c\u4f8b\u5982 .doc \uff1a<\/p>\n

$ mv dir1\/*.doc dir2\/ \r\n<\/pre>\n

\u8fd9\u91cc\u5c31\u4ecb\u7ecd\u8fd9\u4e48\u591a\uff0c\u66f4\u591a\u8be6\u7ec6\u5185\u5bb9\u8bf7\u53c2\u8003\u5b83\u7684\u624b\u518c\u9875\uff1a<\/p>\n

$ man mv \r\n<\/pre>\n
\u5c0f\u7ed3<\/strong><\/div>\n

\u79fb\u52a8\u5c11\u6570\u7684\u6587\u4ef6\u5230\u4e0d\u540c\u76ee\u5f55\u5f88\u5bb9\u6613\uff0c\u4f60\u53ef\u4ee5\u5728 GUI \u6a21\u5f0f\u4e0b\u5355\u51fb\u9f20\u6807\u6216\u8005\u5728 CLI \u6a21\u5f0f\u4e0b\u4f7f\u7528\u5355\u884c\u547d\u4ee4\u6765\u64cd\u4f5c\u3002\u4f46\u662f\uff0c\u5982\u679c\u6709\u6570\u5343\u79cd\u4e0d\u540c\u7684\u6587\u4ef6\u7c7b\u578b\uff0c\u4f60\u5c31\u4f1a\u5f88\u65e0\u8bed\u4e86\u3002\u4e0d\u8fc7\uff0c\u5e78\u8fd0\u7684\u662f\u4f60\u5b66\u4e60\u5b8c\u4e86\u4eca\u5929\u7684\u5c0f\u6280\u5de7\u540e\uff0c\u8fd9\u79cd\u9700\u6c42\u5bf9\u4f60\u6765\u8bf4\u5c31\u4f1a\u53d8\u5f97\u5f88 easy !<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5047\u8bbe dir1 \u7684\u76ee\u5f55\u4e2d\u6709\u591a\u79cd\u7c7b\u578b\u7684\u6587\u4ef6\uff0c\u5982 .pdf .doc .mp3 .mp4 .txt \u7b49\uff0c\u6211\u4eec\u5148\u6765\u67e5 […]<\/p>\n","protected":false},"author":1329,"featured_media":157108,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-157105","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\/157105","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\/1329"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=157105"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/157105\/revisions"}],"predecessor-version":[{"id":157110,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/157105\/revisions\/157110"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/157108"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=157105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=157105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=157105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}