• 第十七章 文件的执行过程



    1. 系统会判断你输入的命令是否绝对路径,是直接执行

    2. 如果是相对路径,系统会判断命令是否存在别名,如果存在,执行别名

    3. 如果命令不存在别名,系统会判断输入的命令是否内置命令,如果是,直接执行

    4. 如果不是内置命令,系统会查询内存的hash缓存表,如果命令存在缓存,则按照缓存执行

    5. 如果hash缓存表中没有命令的缓存,系统会从环境变量PATH中的命令路径查询命令的路径进行执行

    6. 如果PATH变量没有命令的路径,就会报错 command not found


    #查询命令是否为内置命令

    [root@jindada ~]# type -a cd
    cd is a shell builtin
    cd is /usr/bin/cd
    [root@jindada ~]# type -a ls
    ls is aliased to `ls --color=auto'
    ls is /usr/bin/ls

    #查看系统中所有的内置命令

    [root@jindada ~]# help


    #查看当前窗口下所有外部命令的缓存表

    [root@jindada ~]# hash
    hits command
    53 /usr/bin/grep
    1 /usr/bin/egrep
    1 /usr/bin/tail
    6 /usr/bin/file

     


    [root@jindada ~]# /usr/bin/wc /etc/hosts
    2 10 158 /etc/hosts
    [root@jindada ~]# ll /usr/bin/wc
    -rwxr-xr-x. 1 root root 41688 Oct 31 2018 /usr/bin/wc
    [root@jindada ~]# mv /usr/bin/wc /usr/bin/gl
    [root@jindada ~]# wc /etc/hosts
    -bash: /usr/bin/wc: No such file or directory
    [root@jindada ~]# gl /etc/hosts
    2 10 158 /etc/hosts
    [root@jindada ~]# hash
    hits command
    53 /usr/bin/grep
    1 /usr/bin/egrep
    1 /usr/bin/tail
    1 /usr/bin/gl


    #从缓存中删除一个命令的缓存

    [root@jindada ~]# hash -d wc


    [root@jindada ~]# wc /etc/hosts
    -bash: wc: command not found


    [root@jindada ~]# mv /usr/bin/gl /usr/bin/wc
    [root@jindada ~]# wc /etc/hosts
    2 10 158 /etc/hosts


    [root@jindada ~]# mv /usr/bin/wc /usr/sbin/
    [root@jindada ~]# wc /etc/hosts
    -bash: /usr/bin/wc: No such file or directory
    [root@jindada ~]# hash -d wc
    [root@jindada ~]# wc /etc/hosts
    2 10 158 /etc/hosts


    #清空hash缓存表中的所有缓存

    [root@jindada ~]# hash -r
    [root@jindada ~]# hash
    hash: hash table empty

    #里面存放的是系统中的命令的路径,每个路径用:号分割

    [root@jindada ~]# echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

     

  • 相关阅读:
    JSON序列化选项
    JOSN的stringify()和parse()方法
    html5增强元素--续
    html5页面增强元素
    js继承模式
    js常用设计模式
    js跨浏览器事件处理
    前端兴趣浓厚,后端提不起来兴趣
    padding的讲究
    margin的讲究
  • 原文地址:https://www.cnblogs.com/jhno1/p/13324742.html
Copyright © 2020-2023  润新知