{"id":160036,"date":"2019-10-11T11:13:07","date_gmt":"2019-10-11T03:13:07","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=160036"},"modified":"2019-10-17T10:58:47","modified_gmt":"2019-10-17T02:58:47","slug":"linux-alias","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-alias.html","title":{"rendered":"Linux Alias \u547d\u4ee4\u7b80\u5355\u4ecb\u7ecd"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u60a8\u53ef\u4ee5\u901a\u8fc7\u4e3a\u6700\u5e38\u7528\u7684\u547d\u4ee4\u521b\u5efa\u522b\u540d\u6765\u8282\u7701\u4e00\u4e9b\u65f6\u95f4\u3002 \u522b\u540d\u5c31\u50cf\u81ea\u5b9a\u4e49\u5feb\u6377\u65b9\u5f0f\uff0c\u7528\u4e8e\u8868\u793a\u4f7f\u7528\u6216\u4e0d\u4f7f\u7528\u81ea\u5b9a\u4e49\u9009\u9879\u6267\u884c\u7684\u547d\u4ee4\uff08\u6216\u547d\u4ee4\u96c6\uff09\u3002 \u60a8\u53ef\u80fd\u5df2\u5728Linux\u7cfb\u7edf\u4e0a\u4f7f\u7528\u522b\u540d\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

Linux\u7528\u6237\u7ecf\u5e38\u9700\u8981\u53cd\u590d\u4f7f\u7528\u4e00\u4e2a\u547d\u4ee4\u3002 \u4e00\u6b21\u53c8\u4e00\u6b21\u5730\u952e\u5165\u6216\u590d\u5236\u76f8\u540c\u7684\u547d\u4ee4\u4f1a\u964d\u4f4e\u60a8\u7684\u5de5\u4f5c\u6548\u7387\uff0c\u5e76\u5206\u6563\u60a8\u7684\u5b9e\u9645\u64cd\u4f5c\u3002<\/p>\n

\u60a8\u53ef\u4ee5\u901a\u8fc7\u4e3a\u6700\u5e38\u7528\u7684\u547d\u4ee4\u521b\u5efa\u522b\u540d\u6765\u8282\u7701\u4e00\u4e9b\u65f6\u95f4\u3002 \u522b\u540d\u5c31\u50cf\u81ea\u5b9a\u4e49\u5feb\u6377\u65b9\u5f0f\uff0c\u7528\u4e8e\u8868\u793a\u4f7f\u7528\u6216\u4e0d\u4f7f\u7528\u81ea\u5b9a\u4e49\u9009\u9879\u6267\u884c\u7684\u547d\u4ee4\uff08\u6216\u547d\u4ee4\u96c6\uff09\u3002 \u60a8\u53ef\u80fd\u5df2\u5728Linux\u7cfb\u7edf\u4e0a\u4f7f\u7528\u522b\u540d\u3002<\/p>\n

\u5217\u51faLinux\u4e2d\u5f53\u524d\u5b9a\u4e49\u7684\u522b\u540d<\/strong><\/div>\n

\u53ea\u9700\u6267\u884calias\u547d\u4ee4\uff0c\u5373\u53ef\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u770b\u5230\u5df2\u5b9a\u4e49\u522b\u540d\u7684\u5217\u8868\u3002<\/p>\n

[linuxidc@localhost www.linuxidc.com]$ alias\r\nalias egrep='egrep --color=auto'\r\nalias fgrep='fgrep --color=auto'\r\nalias grep='grep --color=auto'\r\nalias l.='ls -d .* --color=auto'\r\nalias ll='ls -l --color=auto'\r\nalias ls='ls --color=auto'\r\nalias running_services='systemctl list-units\u00a0 --type=service\u00a0 --state=running'\r\nalias vi='vim'\r\nalias which='alias | \/usr\/bin\/which --tty-only --read-alias --show-dot --show-tilde'<\/pre>\n

\"\"<\/p>\n

\u5728\u8fd9\u91cc\uff0c\u60a8\u53ef\u4ee5\u770b\u5230\u5728CentOS 7.6\u4e2d\u4e3a\u60a8\u7684\u7528\u6237\u5b9a\u4e49\u7684\u9ed8\u8ba4\u522b\u540d\u3002<\/p>\n

\u5982\u4f60\u6240\u89c1\uff0c\u6267\u884c\u3002<\/p>\n

$ ll<\/pre>\n

\u76f8\u5f53\u4e8e\u8fd0\u884c\uff1a<\/p>\n

ls -l --color=auto<\/pre>\n

\"\"<\/p>\n

\u60a8\u53ef\u4ee5\u4f7f\u7528\u5355\u4e2a\u5b57\u7b26\u521b\u5efa\u522b\u540d\uff0c\u8be5\u522b\u540d\u5c06\u7b49\u540c\u4e8e\u60a8\u9009\u62e9\u7684\u547d\u4ee4\u3002<\/p>\n

<\/p>\n

\u5982\u4f55\u5728Linux\u4e2d\u521b\u5efa\u522b\u540d<\/strong><\/div>\n

<\/strong><\/p>\n

\u521b\u5efa\u522b\u540d\u76f8\u5bf9\u5bb9\u6613\u4e14\u5feb\u901f\u3002 \u60a8\u53ef\u4ee5\u521b\u5efa\u4e24\u79cd\u7c7b\u578b\u7684\u522b\u540d - \u4e34\u65f6\u522b\u540d\u548c\u6c38\u4e45\u522b\u540d\u3002 \u6211\u4eec\u5c06\u56de\u987e\u8fd9\u4e24\u79cd\u7c7b\u578b\u3002<\/p>\n

<\/p>\n

\u521b\u5efa\u4e34\u65f6\u522b\u540d<\/strong><\/span><\/div>\n

<\/strong><\/p>\n

\u60a8\u9700\u8981\u505a\u7684\u662f\u952e\u5165\u5355\u8bcdalias\uff0c\u7136\u540e\u4f7f\u7528\u60a8\u5e0c\u671b\u7528\u4e8e\u6267\u884c\u547d\u4ee4\u7684\u540d\u79f0\uff0c\u540e\u8ddf\u201c=\u201d\u7b26\u53f7\u5e76\u5f15\u7528\u60a8\u5e0c\u671b\u522b\u540d\u7684\u547d\u4ee4\u3002<\/p>\n

\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n

$ alias \u7b80\u79f0='\u4f60\u7684\u81ea\u5b9a\u4e49\u547d\u4ee4\u5728\u8fd9\u91cc'<\/pre>\n

\u8fd9\u662f\u4e00\u4e2a\u5b9e\u9645\u7684\u4f8b\u5b50\uff1a<\/p>\n

$ alias idc='cd \/home\/www\/share'<\/pre>\n

\"\"<\/p>\n

\u7136\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u201cidc\u201d\u5feb\u6377\u65b9\u5f0f\u8f6c\u5230\/home\/www\/share\u76ee\u5f55\u3002 \u8be5\u522b\u540d\u7684\u95ee\u9898\u5728\u4e8e\u5b83\u4ec5\u9002\u7528\u4e8e\u60a8\u5f53\u524d\u7684\u7ec8\u7aef\u4f1a\u8bdd\u3002<\/p>\n

\u5982\u679c\u60a8\u6253\u5f00\u65b0\u7684\u7ec8\u7aef\u4f1a\u8bdd\uff0c\u522b\u540d\u5c06\u4e0d\u518d\u53ef\u7528\u3002 \u5982\u679c\u60a8\u5e0c\u671b\u8de8\u4f1a\u8bdd\u4fdd\u5b58\u522b\u540d\uff0c\u5219\u9700\u8981\u4e00\u4e2a\u6c38\u4e45\u522b\u540d\u3002<\/p>\n

<\/p>\n

\u521b\u5efa\u6c38\u4e45\u522b\u540d<\/strong><\/span><\/div>\n

<\/strong><\/p>\n

\u8981\u5728\u4f1a\u8bdd\u4e4b\u95f4\u4fdd\u7559\u522b\u540d\uff0c\u53ef\u4ee5\u5c06\u5b83\u4eec\u4fdd\u5b58\u5728\u7528\u6237\u7684shell\u914d\u7f6e\u6587\u4ef6\u4e2d\u3002 \u8fd9\u53ef\u4ee5\u662f\uff1a<\/p>\n

    \n
  • Bash \u2013 ~\/.bashrc<\/strong><\/li>\n
  • ZSH \u2013 ~\/.zshrc<\/strong><\/li>\n
  • Fish \u2013 ~\/.config\/fish\/config.fish<\/strong><\/li>\n<\/ul>\n

    \u60a8\u5e94\u8be5\u4f7f\u7528\u7684\u8bed\u6cd5\u51e0\u4e4e\u4e0e\u521b\u5efa\u4e34\u65f6\u522b\u540d\u76f8\u540c\u3002 \u552f\u4e00\u7684\u533a\u522b\u6765\u81ea\u4e8e\u8fd9\u6b21\u4f60\u5c06\u5b83\u4fdd\u5b58\u5728\u6587\u4ef6\u4e2d\u3002 \u4f8b\u5982\uff0c\u5728bash\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u60a8\u559c\u6b22\u7684\u7f16\u8f91\u5668\u6253\u5f00.bashrc\u6587\u4ef6\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

    $ vim ~\/.bashrc<\/pre>\n

    \u5728\u6587\u4ef6\u4e2d\u67e5\u627e\u8981\u4fdd\u7559\u522b\u540d\u7684\u4f4d\u7f6e\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u5c06\u5b83\u4eec\u6dfb\u52a0\u5230\u6587\u4ef6\u7684\u672b\u5c3e\u3002\u51fa\u4e8e\u7ec4\u7ec7\u76ee\u7684\uff0c\u60a8\u53ef\u4ee5\u5728\u522b\u540d\u4e4b\u524d\u7559\u4e0b\u6ce8\u91ca\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

    #\u6211\u7684\u81ea\u5b9a\u4e49\u522b\u540d\r\nalias home=\u201dssh -i ~\/.ssh\/mykep.pem linuxic@192.168.1.199\u201d<\/pre>\n

    \u4fdd\u5b58\u6587\u4ef6\u3002 \u8be5\u6587\u4ef6\u5c06\u5728\u60a8\u7684\u4e0b\u4e00\u4e2a\u4f1a\u8bdd\u4e2d\u81ea\u52a8\u52a0\u8f7d\u3002 \u5982\u679c\u8981\u5728\u5f53\u524d\u4f1a\u8bdd\u4e2d\u4f7f\u7528\u65b0\u5b9a\u4e49\u7684\u522b\u540d\uff0c\u8bf7\u53d1\u51fa\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

    $ source ~\/.bashrc<\/pre>\n

    \u8981\u5220\u9664\u901a\u8fc7\u547d\u4ee4\u884c\u6dfb\u52a0\u7684\u522b\u540d\uff0c\u53ef\u4ee5\u4f7f\u7528unalias\u547d\u4ee4\u53d6\u6d88\u522b\u540d\u3002<\/p>\n

    $ unalias alias_name\r\n$ unalias -a [\u5220\u9664\u6240\u6709\u522b\u540d]<\/pre>\n

    <\/p>\n

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

    <\/strong><\/p>\n

    \u8fd9\u662f\u4e00\u4e2a\u7b80\u77ed\u7684\u793a\u4f8b\uff0c\u8bf4\u660e\u5982\u4f55\u521b\u5efa\u81ea\u5df1\u7684\u522b\u540d\u5e76\u6267\u884c\u5e38\u7528\u547d\u4ee4\uff0c\u800c\u65e0\u9700\u4e00\u6b21\u53c8\u4e00\u6b21\u5730\u952e\u5165\u6bcf\u4e2a\u547d\u4ee4\u3002 \u73b0\u5728\uff0c\u60a8\u53ef\u4ee5\u8003\u8651\u6700\u5e38\u7528\u7684\u547d\u4ee4\uff0c\u5e76\u5728shell\u4e2d\u4e3a\u5b83\u4eec\u521b\u5efa\u5feb\u6377\u65b9\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

    Linux\u7528\u6237\u7ecf\u5e38\u9700\u8981\u53cd\u590d\u4f7f\u7528\u4e00\u4e2a\u547d\u4ee4\u3002 \u4e00\u6b21\u53c8\u4e00\u6b21\u5730\u952e\u5165\u6216\u590d\u5236\u76f8\u540c\u7684\u547d\u4ee4\u4f1a\u964d\u4f4e\u60a8\u7684\u5de5\u4f5c\u6548\u7387\uff0c\u5e76\u5206\u6563\u60a8\u7684\u5b9e\u9645\u64cd […]<\/p>\n","protected":false},"author":63,"featured_media":160042,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-160036","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\/160036","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\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=160036"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/160036\/revisions"}],"predecessor-version":[{"id":160215,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/160036\/revisions\/160215"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/160042"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=160036"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=160036"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=160036"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}