{"id":1001,"date":"2010-08-04T07:11:49","date_gmt":"2010-08-04T13:11:49","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=1001"},"modified":"2010-08-08T06:44:10","modified_gmt":"2010-08-08T12:44:10","slug":"1001","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/1001","title":{"rendered":"\u5b9e\u73b0cp\u547d\u4ee4(5)"},"content":{"rendered":"<p>\u665a\u4e0a7\u70b9\u591a\u7ed93+1\u73ed\u548clinux\u5174\u8da3\u5c0f\u7ec4\u7684\u540c\u5b66\u8bb2\u89e3\u4e86my_cp\u7684\u5b9e\u73b0\u8fc7\u7a0b\u3002\u6574\u4f53\u8fd8\u7b97\u53ef\u4ee5\uff0c\u4e0d\u8fc7\u6211\u4e2a\u4eba\u611f\u89c9\u8fd8\u662f\u6709\u70b9\u7d27\u5f20\uff0c\u4e2a\u522b\u4e4b\u5904\u8bb2\u7684\u4e0d\u662f\u5f88\u6e05\u695a\u3002\u6709\u65f6\u5019\u7adf\u7136\u58f0\u97f3\u90fd\u7834\u97f3\u4e86\uff01 <img src=\"http:\/\/edsionte.com\/techblog\/wordpress\/wp-includes\/images\/smilies\/773d8a13dde2fbdff6039ec3.gif\" alt=\"e43\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> \u770b\u6765\u4ee5\u540e\u8981\u591a\u953b\u70bc\u953b\u70bc\uff01\u4e0d\u80fd\u53ea\u4f1a\u5199\u4e0d\u4f1a\u8bf4\uff01\u6211\u4e0d\u8981\u505a\u5218\u6c38\u82f9\uff08\u8fd9\u4f4d\u8001\u5e08\u7406\u8bba\u77e5\u8bc6\u5145\u88d5\uff0c\u4f46\u662f\u8868\u8fbe\u4e25\u91cd\u4e0d\u9760\u8c31\uff09\uff01<\/p>\n<p>1.\u8bb2\u89e3\u8fc7\u7a0b\u4e2d\u6709\u4e00\u4f4d\u540c\u5b66\u63d0\u51fa\u8fd9\u6837\u7684\u95ee\u9898\uff1a<strong>\u5f53\u6e90\u6587\u4ef6\u662f*.c\u8fd9\u6837\u7684\u5f62\u5f0f\u65f6\uff0cmy_cp\u53ef\u4ee5\u6b63\u786e\u6267\u884c\u5417\u3002<\/strong><\/p>\n<p><strong> <\/strong>\u6211\u5f53\u65f6\u6709\u70b9\u72af\u50bb\uff0c\u7684\u786e\u6211\u5728\u505amy_cp\u7684\u8fc7\u7a0b\u4e2d\u5e76\u6ca1\u6709\u60f3\u5230\u8fd9\u4e2a\u95ee\u9898\uff0c\u4f46\u662f\u6211\u521a\u8bd5\u4e86\u4ee5\u4e0b\u662f\u53ef\u4ee5\u6210\u529f\u6267\u884c\u7684\u3002\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush:c\">gues@huangwei-desktop:~\/code\/shell_command$ .\/my_cp *.c newdir\/\r\ngues@huangwei-desktop:~\/code\/shell_command$ ls -l newdir\/\r\n\u603b\u7528\u91cf 64\r\n-rw-r--r-- 1 gues gues 7799 2010-08-04 21:06 cp_plus2.c\r\n-rw-r--r-- 1 gues gues 1377 2010-08-04 21:06 e 3_6.c\r\n-rw-r--r-- 1 gues gues    0 2010-08-04 21:06 my_cat.c\r\n-rw-r--r-- 1 gues gues 5327 2010-08-04 21:06 my_chmod.c\r\n-rw-r--r-- 1 gues gues 7881 2010-08-04 21:06 my_cp.c\r\n-rw-r--r-- 1 gues gues 7378 2010-08-04 21:06 my_ls.c\r\n-rw-r--r-- 1 gues gues 6271 2010-08-04 21:06 my_shell.c\r\n-rw-rw-rw- 1 gues gues    0 2010-08-04 21:06 test2.c\r\n-rw-r--r-- 1 gues gues    7 2010-08-04 21:06 test.c\r\n-rw-r--r-- 1 gues gues 7378 2010-08-04 21:06 tfile.c\r\n-rw-r--r-- 1 gues gues 6271 2010-08-04 21:06 ttfile.c<\/pre>\n<p>\u65e2\u7136\u53ef\u4ee5\u6210\u529f\uff0c\u90a3\u4e48\u5b83\u5230\u5e95\u901a\u5411my_cp\u56db\u4e2a\u529f\u80fd\u4e2d\u7684\u54ea\u4e00\u4e2a\uff1f\u4ece\u6307\u4ee4\u5f62\u5f0f\u4e0a\u770b\uff0c\u8c8c\u4f3c\u53ea\u6709\u4e00\u4e2a\u6e90\u6587\u4ef6\uff1a*.c\u3002\u4f46\u662f\u4e8b\u5b9e\u4e0a\u8fd9\u4e2a\u6307\u4ee4\u7684\u529f\u80fd\u662f\u5c06\u591a\u4e2a\u6587\u4ef6\u62f7\u8d1d\u5230\u6307\u5b9a\u76ee\u5f55\u3002\u6700\u540e\u6211\u901a\u8fc7\u8c03\u8bd5\u4e00\u4e0b\u5c31\u5f97\u5230\u4e86\u7b54\u6848\uff01\u6211\u5728\u4e3b\u51fd\u6570\u4e00\u5f00\u662f\u5c31\u52a0\u5165\u4e86\u65ad\u70b9\uff1a<\/p>\n<pre class=\"brush:c\">for(i=1;i&lt;\\argc;i++)\/\/\u65ad\u70b9\u5904\r\n{\r\n\/\/the code here was omited\r\n}<\/pre>\n<p>\u7136\u540e\u6211\u6253\u5370argc\u7684\u503c\uff0c\u663e\u793a\u4e3a13\uff01\u6570\u6570\u4e0a\u9762\u7684.c\u6587\u4ef6\u521a\u597d11\u4e2a\uff0c\u52a0\u4e0a.\/my_cp\u548cdir\u521a\u597d13\u4e2a\u53c2\u6570\u3002\u90a3\u4e48\u7b54\u6848\u5c31\u662f\uff1a*.c\u5728\u8f93\u5165\u540e\uff0c\u7cfb\u7edf\u81ea\u52a8\u5c31\u67e5\u627e\u7b26\u5408\u6761\u4ef6\u7684\u6587\u4ef6\uff0c\u5e76\u201c\u6697\u81ea\u201c\u6dfb\u52a0\u5230\u547d\u4ee4\u4e2d\u3002\u56e0\u6b64\u4e0a\u9762\u7684\u547d\u4ee4\u7b49\u540c\u4e8e\uff1a<\/p>\n<pre class=\"brush:c\">.\/my_cp cp_plus2.c my_ls.c test.c   ttfile.c e 3_6.c  my_cat.c  my_chmod.c  my_cp.c  my_shell.c test2.c  tfile.c dir\/<\/pre>\n<p>2.\u4eca\u5929(8\/5)woody\u540c\u5b66\u7559\u8a00\u8bf4\uff0c\u5f53\u51fa\u73b0.\/my_cp test.c .\/.\/.\/test.c\u65f6\u5019\uff0c\u5982\u4f55\u5904\u7406\u5176\u9519\u8bef\u663e\u793a\uff1f<\/p>\n<p>\u8fd9\u4e2a\u95ee\u9898\u5728\u6211\u7684my_cp\u4e2d\u6ca1\u6709\u505a\u5230\u3002\u4f46\u662f\u8981\u907f\u514d\u8fd9\u4e2a\u95ee\u9898\u4e5f\u4e0d\u96be\u3002\u5728cp_single\u51fd\u6570\u4e2d\uff0c\u5f53\u6211\u4eec\u5224\u65ad\u4e86\u76ee\u7684\u6587\u4ef6\u5b58\u5728\u65f6\uff08\u6e90\u6587\u4ef6\u80af\u5b9a\u5b58\u5728\uff0c\u56e0\u4e3a\u5728\u4e3b\u51fd\u6570\u4e2d\u5df2\u7ecf\u5224\u65ad\u8fc7\uff09\uff0c\u53ef\u4ee5\u52a0\u5165\u8fd9\u4e00\u6bb5\uff1a<\/p>\n<pre class=\"brush:c\">\t\tif(stat(src_path,&amp;src_buf)!=0)\r\n\t\t{\r\n\t\t\tprintf(\"In cp_single:open src_file error.\\n\");\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tif(src_buf.st_ino==buf.st_ino)\r\n\t\t{\r\n\t\t\tprintf(\"my_cp: \\\"%s\\\"\u548c\\\"%s\\\"\u4e3a\u540c\u4e00\u6587\u4ef6\\n\",src_path,dest_path);\r\n\t\t\treturn ;\r\n\t\t}<\/pre>\n<p>\u4e3b\u8981\u601d\u60f3\u5c31\u662f\u5206\u522b\u83b7\u53d6\u6e90\u548c\u76ee\u7684\u6587\u4ef6\u7684\u5c5e\u6027\uff0c\u518d\u53bb\u6bd4\u8f83st_ino\uff08\u6587\u4ef6i\u8282\u70b9\u7f16\u53f7\uff09\u662f\u5426\u76f8\u540c\u3002\u53e6\u5916\u8fd8\u8981\u5728cp_directory\u51fd\u6570\u4e2d\u4e5f\u8981\u52a0\u5165\u7c7b\u4f3c\u7684\u4ee3\u7801\uff0c\u56e0\u4e3acp\u547d\u4ee4\u662f\u4e0d\u80fd\u5c06\u672c\u76ee\u5f55\u62f7\u8d1d\u5230\u672c\u76ee\u5f55\u4e0b\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u665a\u4e0a7\u70b9\u591a\u7ed93+1\u73ed\u548clinux\u5174\u8da3\u5c0f\u7ec4\u7684\u540c\u5b66\u8bb2\u89e3\u4e86my_cp\u7684\u5b9e\u73b0\u8fc7\u7a0b\u3002\u6574\u4f53\u8fd8\u7b97\u53ef\u4ee5\uff0c\u4e0d\u8fc7\u6211\u4e2a\u4eba\u611f\u89c9\u8fd8\u662f\u6709\u70b9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[125,107],"class_list":["post-1001","post","type-post","status-publish","format-standard","hentry","category-linuxc","tag-linux","tag-107"],"views":10132,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/1001","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=1001"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/1001\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=1001"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=1001"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=1001"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}