{"id":276375,"date":"2023-07-02T04:04:21","date_gmt":"2023-07-01T20:04:21","guid":{"rendered":"https:\/\/lrxjmw.cn\/mfzywlycyysc.html"},"modified":"2023-07-02T04:04:21","modified_gmt":"2023-07-01T20:04:21","slug":"mfzywlycyysc","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/mfzywlycyysc.html","title":{"rendered":"\u514d\u8d39\u8d44\u6e90\u7f51-\u5229\u7528c\u8bed\u8a00\u5220\u9664\u76ee\u5f55\u4e0b\u6587\u4ef6"},"content":{"rendered":"

\u514d\u8d39\u8d44\u6e90\u7f51-<\/p>\n

\u501f\u52a9c\u8bed\u8a00\u5220\u6389\u76ee\u5f55\u4e0b\u6587\u4ef6<\/p>\n

\u8fd1\u6765\u8fd9\u6bb5\u65f6\u95f4\u5de5\u4f5c\u5185\u5bb9\u662f\u5173\u4e8eLinux<\/a>\u4e0b\u7684\u7b80\u5355\u6587\u4ef6\u64cd\u4f5c\uff0c\u539f\u5148\u5bf9\u4e8eLinux\u7cfb\u7edf<\/a>\u4e0b\u7684\u6587\u4ef6\u64cd\u4f5c\u51fd\u6570\u90fd\u4e0d\u662f\u592a\u719f\u6089linux\uff0c\u7ecf\u8fc7\u6b64\u6b21\u5b9e\u8df5linux find -name \u904d\u5386\u76ee\u5f55<\/strong>\uff0c\u5bf9\u8fd9\u79cd\u51fd\u6570\u4f7f\u7528\u6709\u4e86\u4e00\u5b9a\u7684\u4e86\u89e3<\/p>\n

c\u8bed\u8a00\u5220\u9664\u7535\u8111\u4e2d\u6587\u4ef6_linux\u4e0bc\u8bed\u8a00\u7f16\u7a0b\u8f6f\u4ef6_linux find -name \u904d\u5386\u76ee\u5f55<\/p>\n

\u600e\u6837\u521b\u5efa\u6587\u4ef6\uff0c\u8bfb\u5199\u6587\u4ef6linux find -name \u904d\u5386\u76ee\u5f55<\/strong>\uff0c\u8fd9\u79cd\u7b80\u5355\u7684\u6211\u60f3\u4f60\u4eec\u5e94\u5f53\u662f\u6bd4\u8f83\u719f\u6089\u7684\uff0c\u6211\u6240\u4ecb\u7ecd\u7684\u662f\u600e\u6837\u904d\u5386\u67d0\u4e2a\u76ee\u5f55\uff0c\u4f46\u662f\u5220\u6389\u8be5\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6(\u53ef\u4ee5\u6307\u5b9a\u540e\u7f00\u540d)linux\u547d\u4ee4\u5927\u5168\uff0c\u4f46\u662f\u4e5f\u53ef\u4ee5\u6307\u5b9a<\/p>\n

\u6587\u4ef6\u7684\u66f4\u6539\u65f6\u95f4\u8303\u56f4(\u591a\u5c11\u5c0f\u65f6\u66fe\u7ecf\u7684\u65e7\u6587\u4ef6\u53ef\u4ee5\u5220\u6389)\uff0c\u4e0b\u8fb9\u5c31\u662f\u7b80\u5355\u7684\u51fd\u6570\u5b9e\u73b0\uff0c\u4ec5\u4f9b\u521d\u5b66\u8005\u53c2\u8003(\u867d\u7136\u6211\u4e5f\u662f\u521d\u5b66\u8005(^o^)\/~)<\/p>\n

\n

\n#include \n#include  \n#include  \n#include \n#include \n#include \n#include \n \n#define FILE_MAX_LEN 256\n \nvoid rmv_old_files(const char *path, const char *suf, int hours)\n{\t\n\tchar filename[FILE_MAX_LEN] = {0};\n\tstruct tm *TM;\n\tstruct dirent *dirp;\n\tstruct stat statbuf;\n\tDIR *dp = NULL;\n\ttime_t curr_time;\n\tint nameLen, offset;\n\tchar *chTemp = NULL;\n\t\n\tcurr_time = time((time_t*)NULL);\n\tdp = opendir(path);\n\tif (NULL == dp)\n\t{\n\t\treturn;\n\t}\t\n\twhile((dirp=readdir(dp)) != NULL)\n\t{\n\t\tif (strcmp(dirp->d_name, \".\")==0 || strcmp(dirp->d_name, \"..\")==0)\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\t\tnameLen = strlen(dirp->d_name);\n\t\tchTemp = dirp->d_name;\n\t\tif (*suf != '')\n\t\t{\n\t\t\toffset = nameLen-strlen(suf);\n\t\t\tif (offsetd_name);\n\t\tif (!stat(filename, &statbuf))\n\t\t{\n\t\t\t\/*check the st_mtime of the file, if more than retention_hours ago then delete it*\/\n\t\t\tif (curr_time-statbuf.st_mtime >= hours*3600 && S_ISREG(statbuf.st_mode))\n\t\t\t{\n\t\t\t\tunlink(filename);\n\t\t\t}\n\t\t}\t\t\t\n\t}\n\tclosedir(dp);\n}<\/pre>\n<\/p>\n

\u9644\uff1alinux\u5220\u6389\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u547d\u4ee4<\/a><\/p>\n

\n

\nrm -f \u6307\u5b9a\u76ee\u5f55*<\/pre>\n<\/p>\n

#\u6700\u7cbe\u5178\u7684\u65b9\u5f0f\uff0c\u5220\u6389\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u7c7b\u578b\u7684\u6587\u4ef6<\/p>\n

c\u8bed\u8a00\u5220\u9664\u7535\u8111\u4e2d\u6587\u4ef6_linux\u4e0bc\u8bed\u8a00\u7f16\u7a0b\u8f6f\u4ef6_linux find -name \u904d\u5386\u76ee\u5f55<\/p>\n

\n

\n2.find \u6307\u5b9a\u76ee\u5f55 -type f -delete\u6216find \u6307\u5b9a\u76ee\u5f55 -type f -exec rm -f {} ;\n<\/pre>\n<\/p>\n

#\u7528find\u547d\u4ee4\u67e5\u627e\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u666e\u901a\u6587\u4ef6\u5e76\u5220\u6389or\u7528find\u547d\u4ee4\u7684\u5904\u7406\u52a8\u4f5c\u5c06\u5176\u5220\u6389<\/p>\n

\n

\n3.find \u6307\u5b9a\u76ee\u5f55 -type f | xargs rm -f\n<\/pre>\n<\/p>\n

c\u8bed\u8a00\u5220\u9664\u7535\u8111\u4e2d\u6587\u4ef6_linux find -name \u904d\u5386\u76ee\u5f55_linux\u4e0bc\u8bed\u8a00\u7f16\u7a0b\u8f6f\u4ef6<\/p>\n

#\u7528\u4e8e\u53c2\u6570\u5217\u8868\u8fc7\u957f;\u8981\u5220\u6389\u7684\u6587\u4ef6\u592a\u591a<\/p>\n

\n

\n4.rm-f `find \u6307\u5b9a\u76ee\u5f55 -type f`\n<\/pre>\n<\/p>\n

#\u5220\u6389\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u5168\u90e8\u666e\u901a\u6587\u4ef6<\/p>\n

\n

\n5.for delete in `ls \u2013l \u6307\u5b9a\u76ee\u5f55\u8def\u5f84`;do rm -f * ;done\n<\/pre>\n<\/p>\n

#\u7528for\u5faa\u73af\u53e5\u5b50\u5220\u6389\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u7c7b\u578b\u7684\u6587\u4ef6<\/p>\n

\u514d\u8d39\u8d44\u6e90\u7f51-<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5229\u7528c\u8bed\u8a00\u5220\u9664\u76ee\u5f55\u4e0b\u6587\u4ef6\u5982\u4f55\u521b\u5efa\u6587\u4ef6\uff0c\u8bfb\u5199\u6587\u4ef6\uff0c\u8fd9\u4e9b\u7b80\u5355\u7684\u6211\u60f3\u5927\u5bb6\u5e94\u8be5\u662f\u6bd4\u8f83\u719f\u6089\u7684\uff0c\u6211\u6240\u4ecb\u7ecd\u7684\u662f\u5982\u4f55\u904d\u5386\u67d0\u4e2a\u76ee\u5f55\uff0c\u5e76\u4e14\u5220\u9664\u8be5\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6(\u53ef\u4ee5\u6307\u5b9a\u540e\u7f00\u540d)\uff0c\u5e76\u4e14\u4e5f\u53ef\u4ee5\u6307\u5b9a\u9644\uff1alinux\u5220\u9664\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u547d\u4ee4#\u6700\u7ecf\u5178\u7684\u65b9\u6cd5\uff0c\u5220\u9664\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u7c7b\u578b\u7684\u6587\u4ef6#\u5220\u9664\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u5168\u90e8\u666e\u901a\u6587\u4ef6#\u7528for\u5faa\u73af\u8bed\u53e5\u5220\u9664\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u7c7b\u578b\u7684\u6587\u4ef6<\/p>\n","protected":false},"author":1,"featured_media":276376,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[999],"class_list":["post-276375","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tougao","tag-999"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/276375","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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=276375"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/276375\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/276376"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=276375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=276375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=276375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}