{"id":223660,"date":"2021-07-31T08:30:04","date_gmt":"2021-07-31T00:30:04","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=223660"},"modified":"2021-07-28T16:31:08","modified_gmt":"2021-07-28T08:31:08","slug":"bash-symlink-locate","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/bash-symlink-locate.html","title":{"rendered":"Bash \u811a\u672c\u5b9e\u4f8b\uff1a\u83b7\u53d6\u7b26\u53f7\u94fe\u63a5\u7684\u76ee\u6807\u4f4d\u7f6e"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u6211\u4eec\u90fd\u719f\u6089 Linux \u4e2d\u7684\u7b26\u53f7\u94fe\u63a5\uff0c\u901a\u5e38\u79f0\u4e3a\u7b26\u53f7\u94fe\u63a5\u6216\u8f6f\u94fe\u63a5\uff0c\u7b26\u53f7\u94fe\u63a5\u662f\u6307\u5411\u4efb\u4f55\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u53e6\u4e00\u4e2a\u6587\u4ef6\u6216\u76ee\u5f55\u7684\u7279\u5b9a\u6587\u4ef6\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u672c\u6587\u5c06\u4ecb\u7ecd Linux \u4e2d\u7b26\u53f7\u94fe\u63a5\u7684\u57fa\u7840\u77e5\u8bc6\uff0c\u5e76\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 bash \u811a\u672c\u6765\u83b7\u53d6\u7b26\u53f7\u94fe\u63a5\u7684\u76ee\u6807\u4f4d\u7f6e\u3002<\/p>\n

\u7b26\u53f7\u94fe\u63a5\u7684\u7c7b\u578b<\/strong><\/div>\n

\u4e3b\u8981\u6709\u4e24\u79cd\u7c7b\u578b\u7684\u7b26\u53f7\u94fe\u63a5\uff0c\u5373\uff1a<\/p>\n

\u786c\u94fe\u63a5\uff1a<\/strong>\u786c\u94fe\u63a5\u662f\u6307\u5411\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\u6216\u76ee\u5f55\u7684\u76f4\u63a5\u6307\u9488\u3002\u786c\u94fe\u63a5\u53ea\u80fd\u5728\u4e0e\u76ee\u6807\u6587\u4ef6\u76f8\u540c\u7684\u6587\u4ef6\u7cfb\u7edf\u4e2d\u521b\u5efa\u3002<\/p>\n

\u8f6f\u8fde\u63a5\uff1a<\/strong>\u8f6f\u94fe\u63a5\u662f\u6587\u4ef6\u6216\u76ee\u5f55\u7684\u95f4\u63a5\u5feb\u6377\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5b58\u5728\u4e8e\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u4efb\u4f55\u4f4d\u7f6e\u3002\u8f6f\u94fe\u63a5\u53ef\u4ee5\u6307\u5411\u4e0d\u540c\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\u3002<\/p>\n

\u5982\u4f55\u521b\u5efa\u7b26\u53f7\u94fe\u63a5<\/strong><\/div>\n

\u8981\u5728 Linux \u4e2d\u521b\u5efa\u7b26\u53f7\u94fe\u63a5\uff0c\u6211\u4eec\u4f7f\u7528 ln<\/code> \u547d\u4ee4\u3002\u6267\u884c\u4e0d\u5e26\u9009\u9879\u7684\u547d\u4ee4\u4f1a\u521b\u5efa\u6307\u5411\u6307\u5b9a\u76ee\u6807\u6587\u4ef6\u7684\u786c\u94fe\u63a5\u3002<\/p>\n

ln<\/code> \u547d\u4ee4\u7684\u4e00\u822c\u8bed\u6cd5\u662f\uff1a<\/p>\n

\r\nln [OPTIONS]  \r\n<\/path><\/target><\/pre>\n

\u5982\u8981\u521b\u5efa\u8f6f\u94fe\u63a5\uff0c\u9700\u8981\u6dfb\u52a0 -s<\/code> \u9009\u9879\uff1a<\/p>\n

\r\nln -s [OPTION]  \r\n<\/path><\/target><\/pre>\n
\u5b9e\u4f8b\u4e00\uff1a\u521b\u5efa\u6587\u4ef6\u7684\u8f6f\u8fde\u63a5<\/strong><\/div>\n

\u4ee5\u4e0b\u547d\u4ee4\u5728\u6211\u4eec\u7684\u4e3b\u76ee\u5f55\u4e2d\u521b\u5efa\u6307\u5411\/var\/log\/audit\/audit.log<\/code>\u6587\u4ef6\u7684\u8f6f\u94fe\u63a5\uff1a<\/p>\n

\r\n[root@localhost ~]# ln -s \/var\/log\/audit\/audit.log ~\/audit.log\r\n<\/pre>\n

\"\"<\/p>\n

\u5b9e\u4f8b\u4e8c\uff1a\u521b\u5efa\u76ee\u5f55\u7684\u8f6f\u8fde\u63a5<\/strong><\/div>\n

\u4ee5\u4e0b\u547d\u4ee4\u5728\u6211\u4eec\u7684\u4e3b\u76ee\u5f55\u4e2d\u521b\u5efa\u6307\u5411\/var\/log<\/code>\u76ee\u5f55\u7684\u8f6f\u94fe\u63a5\uff1a<\/p>\n

\r\n[root@localhost ~]# ln -s \/var\/log ~\/log\r\n<\/pre>\n

\"\"<\/p>\n

\u5982\u4f55\u5220\u9664\u7b26\u53f7\u94fe\u63a5<\/strong><\/div>\n

\u8981\u5220\u9664\u7b26\u53f7\u94fe\u63a5\uff0c\u6211\u4eec\u4f7f\u7528\u547d\u4ee4 unlink<\/code> \u540e\u8ddf\u8981\u5220\u9664\u7684\u7b26\u53f7\u94fe\u63a5\u7684\u8def\u5f84\u3002<\/p>\n

\r\n[root@localhost ~]# unlink ~\/log\r\n<\/pre>\n

\u4e0b\u56fe\u53ef\u770b\u5230\uff0clog\u7684\u5feb\u6377\u65b9\u5f0f\u6ca1\u6709\u4e86\u3002
\n\"\"
\n\u6ce8\u610f\uff1a\u5982\u679c\u5220\u9664\u76ee\u6807\u6587\u4ef6\u6216\u76ee\u5f55\uff0c\u8bf7\u8bb0\u5f97\u5220\u9664\u7b26\u53f7\u94fe\u63a5\uff0c\u56e0\u4e3a\u7b26\u53f7\u94fe\u63a5\u4e0d\u4f1a\u968f\u7740\u6587\u4ef6\u7684\u5220\u9664\u800c\u5220\u9664\u3002<\/p>\n

\u5982\u4f55\u83b7\u53d6\u7b26\u53f7\u94fe\u63a5\u7684\u76ee\u6807\u6587\u4ef6\u6216\u76ee\u5f55<\/strong><\/div>\n

\u6bcf\u4e2a\u7b26\u53f7\u94fe\u63a5\u90fd\u4f1a\u6307\u5411\u4e00\u4e2a\u76ee\u6807\u6587\u4ef6\u6216\u76ee\u5f55\uff08\u9664\u975e\u635f\u574f\uff09\u3002\u8981\u83b7\u53d6\u7b26\u53f7\u94fe\u63a5\u7684\u76ee\u6807\u6587\u4ef6\/\u76ee\u5f55\uff0c\u6211\u4eec\u4f7f\u7528readlink<\/code>\u547d\u4ee4\u663e\u793a\u7b26\u53f7\u94fe\u63a5\u7684\u76ee\u6807\u3002<\/p>\n

\u4f8b\u5982\uff0c\u8981\u83b7\u53d6\u6211\u4eec\u5728\u524d\u9762\u90e8\u5206\u4e2d\u521b\u5efa\u7684 audit.log<\/code> \u6587\u4ef6\u7684\u76ee\u6807\uff0c\u6211\u4eec\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n

\r\n[root@localhost ~]# readlink ~\/audit.log \r\n\/var\/log\/audit\/audit.log\r\n<\/pre>\n
\u83b7\u53d6\u7b26\u53f7\u94fe\u63a5\u7684 Bash \u811a\u672c<\/strong><\/div>\n

\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 bash \u811a\u672c\uff0c\u8be5\u811a\u672c\u63a5\u53d7\u8def\u5f84\u5e76\u5217\u51fa\u6240\u6709\u7b26\u53f7\u94fe\u63a5\u53ca\u5176\u76ee\u6807\u6587\u4ef6\u6216\u76ee\u5f55\uff1a<\/p>\n

\r\n[root@localhost ~]# vim symlink.sh \r\n#!\/bin\/bash\r\nread -p \"Provide the directory to evaluate: \" target_dir\r\ncd $target_dir\r\nlinks=$(find . -maxdepth 1 -type l -ls | awk '{print $11}')\r\nfor link in $links\r\ndo\r\n    echo \"$link -> $(readlink $link)\"\r\ndone\r\n<\/pre>\n

\"\"
\n\u8be5\u811a\u672c\u9996\u5148\u8be2\u95ee\u7528\u6237\u8981\u83b7\u53d6\u7684\u76ee\u5f55\u3002\u7136\u540e\uff0c\u811a\u672c\u8f6c\u5230\u63d0\u4f9b\u7684\u76ee\u5f55\u5e76\u627e\u5230\u76ee\u5f55\u4e2d\u7684\u6240\u6709\u7b26\u53f7\u94fe\u63a5\uff0c\u5e76\u5c06\u8f93\u51fa\u4f20\u9012\u7ed9awk<\/code>\u547d\u4ee4\u3002<\/p>\n

awk<\/code> \u8f93\u51fa\u5e76\u5b9a\u4f4d\u7b26\u53f7\u94fe\u63a5\uff0c\u5e76\u5c06\u5b83\u4eec\u4fdd\u5b58\u5230\u4e00\u4e2a\u540d\u4e3a links \u7684\u53d8\u91cf\u4e2d\u3002<\/p>\n

\u7136\u540e\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u5faa\u73af\uff0c\u6293\u53d6links\u53d8\u91cf\u4e2d\u7684\u6bcf\u4e2a\u94fe\u63a5\uff0c\u5e76\u4f7f\u7528 readlink<\/code> \u547d\u4ee4\u83b7\u53d6\u5b83\u4eec\u7684\u76ee\u6807\u4f4d\u7f6e\u3002<\/p>\n

\u6700\u540e\uff0c\u663e\u793a\u7b26\u53f7\u94fe\u63a5\u548c\u76ee\u6807\u76ee\u5f55\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u8f93\u51fa\uff1a<\/p>\n

\r\n[root@localhost ~]# .\/symlink.sh \r\nProvide the directory to evaluate: \/etc\r\n.\/rc.local -> rc.d\/rc.local\r\n.\/redhat-release -> centos-release\r\n.\/system-release -> centos-release\r\n.\/init.d -> rc.d\/init.d\r\n.\/rc0.d -> rc.d\/rc0.d\r\n.\/rc1.d -> rc.d\/rc1.d\r\n.\/rc2.d -> rc.d\/rc2.d\r\n.\/rc3.d -> rc.d\/rc3.d\r\n.\/rc4.d -> rc.d\/rc4.d\r\n.\/rc5.d -> rc.d\/rc5.d\r\n.\/rc6.d -> rc.d\/rc6.d\r\n.\/localtime -> ..\/usr\/share\/zoneinfo\/Asia\/Shanghai\r\n.\/mtab -> ..\/proc\/self\/mounts\r\n.\/yum.conf -> dnf\/dnf.conf\r\n.\/grub2.cfg -> ..\/boot\/grub2\/grub.cfg\r\n<\/pre>\n

\"\"<\/p>\n

\u603b\u7ed3<\/strong><\/div>\n

\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u5728 Linux \u4e2d\u4f7f\u7528\u7b26\u53f7\u94fe\u63a5\u7684\u57fa\u7840\u77e5\u8bc6\u3002\u7136\u540e\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u811a\u672c\u6765\u67e5\u627e\u6307\u5b9a\u76ee\u5f55\u4e2d\u7684\u7b26\u53f7\u94fe\u63a5\u5e76\u663e\u793a\u5b83\u4eec\u7684\u6e90\u548c\u76ee\u6807\u4f4d\u7f6e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u672c\u6587\u5c06\u4ecb\u7ecd Linux \u4e2d\u7b26\u53f7\u94fe\u63a5\u7684\u57fa\u7840\u77e5\u8bc6\uff0c\u5e76\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 bash \u811a\u672c\u6765\u83b7\u53d6\u7b26\u53f7\u94fe\u63a5\u7684\u76ee\u6807\u4f4d\u7f6e\u3002 \u4e3b\u8981 […]<\/p>\n","protected":false},"author":309,"featured_media":223661,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-223660","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\/223660","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\/309"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=223660"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/223660\/revisions"}],"predecessor-version":[{"id":223667,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/223660\/revisions\/223667"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/223661"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=223660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=223660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=223660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}