{"id":219220,"date":"2021-06-10T10:45:04","date_gmt":"2021-06-10T02:45:04","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=219220"},"modified":"2021-05-24T09:12:24","modified_gmt":"2021-05-24T01:12:24","slug":"automatically-clear-links","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/automatically-clear-links.html","title":{"rendered":"\u5982\u4f55\u81ea\u52a8\u6e05\u9664\u6307\u5b9a\u6587\u4ef6\u5939\u4e0b\u7684\u7b26\u53f7\u94fe\u63a5"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86\u4f7f\u7528\u811a\u672c\u5b9e\u73b0\u81ea\u52a8\u6e05\u9664\u6307\u5b9a\u6587\u4ef6\u5939\u4e0b\u4e22\u5931\u94fe\u63a5\u6587\u4ef6\u7684\u7b26\u53f7\u94fe\u63a5,\u672c\u6587\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u7684\u975e\u5e38\u8be6\u7ec6\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u501f\u9274\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u811a\u672c\u53ef\u6e05\u9664\uff0c\u6307\u5b9a\u6587\u4ef6\u5939\u4e0b\uff0c\u5bf9\u89c6\u94fe\u63a5\u6587\u4ef6\u7684\u7b26\u53f7\u94fe\u63a5\u3002<\/p>\n

\u5728\u4f7f\u7528Linux\u65f6\uff0c\u5e38\u5e38\u4f1a\u4e3a\u81ea\u5df1\u8bb8\u591a\u6587\u4ef6\u6216\u8005\u7a0b\u5e8f\u5efa\u7acb\u7b26\u53f7\u94fe\u63a5\uff0c\u8fd9\u6837\u5c31\u4e0d\u7528\u6bcf\u6b21\u90fd\u5230\u5bf9\u5e94\u7684\u6587\u4ef6\u5939\u4e0b\u53bb\u5bfb\u627e\u5bf9\u5e94\u7684\u6587\u4ef6\u800c\u53ea\u9700\u8981\u5bf9\u9700\u8981\u7ecf\u5e38\u8bbf\u95ee\u7684\u6587\u4ef6\u5efa\u7acb\u7b26\u53f7\u94fe\u63a5\u5c31\u53ef\u4ee5\u4e86\uff0c\u8fd9\u6837\u5c31\u80fd\u628a\u4f60\u5e38\u9700\u8981\u8bbf\u95ee\u7684\u6587\u4ef6\u653e\u5230\u684c\u9762\u4e0a\uff0c\u6216\u8005\u6307\u5b9a\u5230\u53e6\u5916\u4e00\u4e2a\u6587\u4ef6\u5939\u4e2d\u3002<\/p>\n

\u8fd9\u6837\u8bbf\u95ee\u65f6\uff0c\u65b9\u4fbf\u4e86\u5f88\u591a\uff0c\u4f46\u662f\u7528\u5b8c\u4e4b\u540e\u5f80\u5f80\u7559\u4e0b\u8bb8\u591a\u7684\u7b26\u53f7\u94fe\u63a5\uff0c\u8fd9\u4e9b\u94fe\u63a5\u9700\u8981\u7528\u6237\u81ea\u5df1\u624b\u52a8\u786e\u8ba4\u662f\u5426\u53ef\u4ee5\u5220\u9664\uff0c\u4e3alinux\u7684\u4f7f\u7528\u5e26\u6765\u5f88\u591a\u7684\u4e0d\u65b9\u4fbf\uff0c\u4f7f\u7528\u8be5\u811a\u672c\u5c31\u80fd\u89e3\u653e\u4f60\u7684\u53cc\u624b\uff0c\u53ea\u9700\u8981\u6267\u884c\u4e00\u4e0b\u811a\u672c\uff0c\u5c31\u80fd\u5c06\u5bf9\u5e94\u6587\u4ef6\u5939\u4e0b\u6ca1\u6709\u7528\u7684\u7b26\u53f7\u94fe\u63a5\u6e05\u9664\u3002<\/p>\n

\r\n#!\/bin\/bash\r\n# \u4e00\u4e2a\u53ef\u4ee5\u6d4b\u8bd5\u94fe\u63a5\u65ad\u6389\u7684\u7b26\u53f7\u94fe\u63a5\u7684\u6587\u4ef6\uff0c\u5e76\u4e14\u53ef\u4ee5\u8f93\u51fa\u5b83\u4eec\u6307\u5411\u7684\u6587\u4ef6\r\n# \u4ee5\u4fbf\u4e8e\u5b83\u4eec\u53ef\u4ee5\u628a\u8f93\u51fa\u63d0\u4f9b\u7ed9xargs\u6765\u8fdb\u884c\u5904\u7406 :)\r\n# \u6bd4\u5982. broken-link.sh \/somedir \/someotherdir|xargs rm\r\n#\r\n#\u4e0b\u8fb9\u7684\u65b9\u6cd5, \u4e0d\u7ba1\u600e\u4e48\u8bf4, \u90fd\u662f\u4e00\u79cd\u66f4\u597d\u7684\u529e\u6cd5:\r\n#\r\n#find \"somedir\" -type l -print0|\\\r\n#xargs -r0 file|\\\r\n#grep \"broken symbolic\"|\r\n#sed -e 's\/^\\|: *broken symbolic.*$\/\"\/g'\r\n#\r\n#\u4f46\u8fd9\u4e0d\u662f\u4e00\u4e2a\u7eaf\u7cb9\u7684bash\u811a\u672c, \u6700\u8d77\u7801\u73b0\u5728\u4e0d\u662f.\r\n#\u6ce8\u610f: \u8c28\u9632\u5728\/proc\u6587\u4ef6\u7cfb\u7edf\u548c\u4efb\u4f55\u6b7b\u5faa\u73af\u94fe\u63a5\u4e2d\u4f7f\u7528!\r\n##############################################################\r\n#\u5982\u679c\u6ca1\u6709\u53c2\u6570\u88ab\u4f20\u9012\u5230\u811a\u672c\u4e2d, \u90a3\u4e48\u5c31\u4f7f\u7528\r\n#\u5f53\u524d\u76ee\u5f55. \u5426\u5219\u5c31\u662f\u7528\u4f20\u9012\u8fdb\u6765\u7684\u53c2\u6570\u4f5c\u4e3a\u76ee\u5f55\r\n#\u6765\u641c\u7d22.\r\n####################\r\n[ $# -eq 0 ] && directorys=`pwd` || directorys=$@\r\n \r\n#\u7f16\u5199\u51fd\u6570linkchk\u7528\u6765\u68c0\u67e5\u4f20\u9012\u8fdb\u6765\u7684\u76ee\u5f55\u6216\u6587\u4ef6\u662f\u5426\u662f\u94fe\u63a5,\r\n#\u5e76\u5224\u65ad\u8fd9\u4e9b\u6587\u4ef6\u6216\u76ee\u5f55\u662f\u5426\u5b58\u5728. \u7136\u540e\u6253\u5370\u5b83\u4eec\u6240\u6307\u5411\u7684\u6587\u4ef6.\r\n#\u5982\u679c\u4f20\u9012\u8fdb\u6765\u7684\u5143\u7d20\u5305\u542b\u5b50\u76ee\u5f55,\r\n#\u90a3\u4e48\u628a\u5b50\u76ee\u5f55\u4e5f\u653e\u5230linkcheck\u51fd\u6570\u4e2d\u5904\u7406, \u8fd9\u6837\u5c31\u8fbe\u5230\u4e86\u9012\u5f52\u7684\u76ee\u7684.\r\n##########\r\nlinkchk () {\r\n  for element in $1\/*; do\r\n    [ -h \"$element\" -a ! -e \"$element\" ] && echo \\\"$element\\\"\r\n    [ -d \"$element\" ] && linkchk $element\r\n    # \u5f53\u7136, '-h'\u7528\u6765\u6d4b\u8bd5\u7b26\u53f7\u94fe\u63a5, '-d'\u7528\u6765\u6d4b\u8bd5\u76ee\u5f55.\r\n  done\r\n}\r\n#\u628a\u6bcf\u4e2a\u4f20\u9012\u5230\u811a\u672c\u7684\u53c2\u6570\u90fd\u9001\u5230linkchk\u51fd\u6570\u4e2d\u8fdb\u884c\u5904\u7406,\r\n#\u68c0\u67e5\u662f\u5426\u6709\u53ef\u7528\u76ee\u5f55. \u5982\u679c\u6ca1\u6709, \u90a3\u4e48\u5c31\u6253\u5370\u9519\u8bef\u6d88\u606f\u548c\r\n#\u4f7f\u7528\u4fe1\u606f.\r\n################\r\nfor directory in $directorys; do\r\n  if [ -d $directory ]\r\n    then linkchk $directory\r\n    else\r\n      echo \"$directory is not a directory\"\r\n      echo \"Usage: $0 dir1 dir2 ...\"\r\n  fi\r\n  done\r\nexit 0\r\n# \u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6 name\r\nandrew@andrew:\/work\/bash\/src$ touch name\r\n# \u4e3aname\u521b\u5efa\u7b26\u53f7\u94fe\u63a5\r\nandrew@andrew:\/work\/bash\/src$ ln -s name aaa\r\n# \u5220\u9664name\u6587\u4ef6\uff0c aaa\u5c06\u4f1a\u53d8\u6210\u4e22\u5931\u94fe\u63a5\u6587\u4ef6\u7684\u7b26\u53f7\u94fe\u63a5\r\nandrew@andrew:\/work\/bash\/src$ rm name\r\n# \u67e5\u770baaa\u4e3a\u6267\u884c\u5f53\u524d\u76ee\u5f55\u4e0b\u7684name\u7684\u7b26\u53f7\u94fe\u63a5\u6587\u4ef6\r\nandrew@andrew:\/work\/bash\/src$ ls -l\r\n\u603b\u7528\u91cf 44\r\nlrwxrwxrwx 1 andrew andrew  4 2\u6708  1 13:20 aaa -> name\r\n-rwxrwxr-x 1 andrew andrew 8656 1\u6708 30 14:46 a.out\r\n-rw-rw-r-- 1 andrew andrew 1887 2\u6708  1 13:08 broken_link.sh\r\n-rw-rw-r-- 1 andrew andrew 322 1\u6708 29 13:08 echo_unique.sh\r\n-rw-rw-r-- 1 andrew andrew 1513 1\u6708 29 15:55 escape_charater.sh\r\n-rw-rw-r-- 1 andrew andrew 279 1\u6708 30 13:48 exit_example.sh\r\n-rw-rw-r-- 1 andrew andrew 199 2\u6708  1 11:52 if_else_more.sh\r\n-rw-rw-r-- 1 andrew andrew 1946 1\u6708 30 21:03 if_true.sh\r\n-rw-rw-r-- 1 andrew andrew 337 1\u6708 29 14:02 single_quotation_mark.sh\r\n-rw-rw-r-- 1 andrew andrew 864 2\u6708  1 12:00 test.c\r\n# \u8c03\u7528\u811a\u672c\u6e05\u9664\u5f53\u524d\u6587\u4ef6\u5939\u4e2d\uff0c\u4e22\u5931\u94fe\u63a5\u6587\u4ef6\u7684\u7b26\u53f7\u94fe\u63a5\r\nandrew@andrew:\/work\/bash\/src$ bash broken_link.sh .\/ | xargs rm\r\nandrew@andrew:\/work\/bash\/src$ ls -l\r\n\u603b\u7528\u91cf 44\r\n-rwxrwxr-x 1 andrew andrew 8656 1\u6708 30 14:46 a.out\r\n-rw-rw-r-- 1 andrew andrew 1887 2\u6708  1 13:08 broken_link.sh\r\n-rw-rw-r-- 1 andrew andrew 322 1\u6708 29 13:08 echo_unique.sh\r\n-rw-rw-r-- 1 andrew andrew 1513 1\u6708 29 15:55 escape_charater.sh\r\n-rw-rw-r-- 1 andrew andrew 279 1\u6708 30 13:48 exit_example.sh\r\n-rw-rw-r-- 1 andrew andrew 199 2\u6708  1 11:52 if_else_more.sh\r\n-rw-rw-r-- 1 andrew andrew 1946 1\u6708 30 21:03 if_true.sh\r\n-rw-rw-r-- 1 andrew andrew 337 1\u6708 29 14:02 single_quotation_mark.sh\r\n-rw-rw-r-- 1 andrew andrew 864 2\u6708  1 12:00 test.c\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u811a\u672c\u53ef\u6e05\u9664\uff0c\u6307\u5b9a\u6587\u4ef6\u5939\u4e0b\uff0c\u5bf9\u89c6\u94fe\u63a5\u6587\u4ef6\u7684\u7b26\u53f7\u94fe\u63a5\u3002 \u5728\u4f7f\u7528Linux\u65f6\uff0c\u5e38\u5e38\u4f1a\u4e3a\u81ea\u5df1\u8bb8\u591a\u6587\u4ef6\u6216\u8005\u7a0b\u5e8f\u5efa\u7acb\u7b26\u53f7\u94fe […]<\/p>\n","protected":false},"author":1479,"featured_media":195492,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-219220","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\/219220","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\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=219220"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/219220\/revisions"}],"predecessor-version":[{"id":219225,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/219220\/revisions\/219225"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/195492"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=219220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=219220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=219220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}