Command lookup mode for Linux commands

Source: Internet
Author: User
Tags aliases builtin delete cache


  • 1 type of command

    The command types in     linux are divided into two classes, one for the command that comes with the shell, the internal command, and the other for the command program on the filesystem, which is the external command .          Advantages of INTERNAL Commands:  command program in-memory, use the faster          related commands:  type,enable            type -  View command type (itself also internal command)                  type command            enable -   Disable or enable a specified internal command                  enable [options] COMMAND                     enable  list all internal commands                      enable -n  command  disable specifying internal naming    &Nbsp;                enable  COMMAND  enable specified internal commands
  • 2 External Command lookup order

    The      command is found on the system, in essence, to find the command program under a path. The path of the system lookup is saved through the path variable in     linux. After the found program file is properly executed, The file path that it finds is saved to the hash table. The         hash table, which is used to cache the command path that has been executed successfully, is saved to a specific memory space .          Related Variables:             path variable Save default value (centos6.x)             #  echo  $PATH                 /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin             :/usr/sbin:/usr/bin:/root/bin          Related Commands: which,whereis,hash             which -  Display command full path                  which command            whereis -  Show command path and help document path                  whereis command             hash -  Forget or display the cache information in the hash table                  hash  Listing Hash Table information                 hash -d  COMMAND   Delete cache of specified commands in the hash table                  hash -r  Empty Hash table
  • 3 Command aliases

    Alias-command alias Create alias Name= ' VALUE ' example: Alias hh= ' echo hhhh ' Unalias-alias Unalias name
  • 4 Find order Proofs

    • The order of 4.1 hash and path

      Preparation link:     View whoami path     # which whoami     /usr/bin/whoami     Show current PATH value     # echo  $PATH      /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin     :/usr/bin:/root/bin     Empty Hash Table     # hash -r     # hash    hash: hash table empty Experimental Steps:      execute whoami to save its path to the hash table .     then move the WhoAmI file to another directory in path .     The WhoAmI command is executed again, and if the WhoAmI command is displayed correctly,     the WhoAmI program file is found in path, the lookup order is path takes precedence over hash, and vice versa .     # whoami            root     # hash        hits     command    1    /usr/bin/whoami    # mv /usr/bin/whoami /bin           # whoami                -bash: /usr/bin/whoami: No such file  or directory     cannot be found, proving to be the WhoAmI path found in the hash table. So hash takes precedence over path.
    • 4.2 Internal and external order

      Preparation session:     PWD is an internal command     # type pwd    pwd  is a shell builtin    pwd file is located on the path     # which  pwd    /bin/pwd     Empty Hash Table     # hash  -r     hash: hash table empty     disable PWD internal commands, Make it use external commands to perform pwd    # enable -n pwd experimental steps:     Cache the path of the PWD command to the hash table, and then copy the WhoAmI command to the path recorded in the hash, which is named pwd.    , which enables the internal command of the PWD command to execute pwd.      If the result shown is a result of WhoAmI, it is queried from the hash table, otherwise the internal command is queried. Vice versa .    # pwd            show current working directory path     centos6.example.com     # hash    hits    command        1    /bin/pwd    # cp /usr/sbin/whoami /bin/pwd        Copy the Whomai command to/bin and rename it to pwd    cp: overwrite  '/bin/pwd '?  y     # pwd          Show Current user name      root    # enable pwd   enable pwd internal command     #  pwd    /root     results PWD Displays the original information, proving that internal commands take precedence over external commands
    • 4.3 Alias and external order

      Preparation: Define an alias with the same name as PWD # alias pwd= ' echo Hello ' enable pwd internal command # Enabling PWD Experiment step: Use the PWD command to view the results. If the output hello, the alias is better than the inner and vice versa. # alias pwd= ' echo Hello ' # enable PWD # pwd Hello results show alias is better than internal command
  • 5 Summary

    The      command is divided into:  internal commands and external commands      commands:  type,enable,hash,which,whereis, alias,unalias     variable:  path (Save command Lookup path, separated by:)      command Query order is:          alias ->  Internal Command  -> hash -> path      Supplemental:          When using aliases, use the command itself temporarily. Implementation Method:             \COMMAND              ' COMMAND '               "COMMAND"             /path/to/command    absolute path to use command              example:                 # alias echo= ' Echo 123 '                 # echo abc                 123 abc                 # \echo  Abc                abc
Command lookup mode for Linux commandsCommand lookup mode for Linux commands
  • 1 type of command

    The command types in     linux are divided into two classes, one for the command that comes with the shell, the internal command, and the other for the command program on the filesystem, which is the external command .          Advantages of INTERNAL Commands:  command program in-memory, use the faster          related commands:  type,enable            type -  View command type (itself also internal command)                  type command            enable -   Disable or enable a specified internal command                  enable [options] COMMAND                     enable  list all internal commands                      enable -n  command  disable specifying internal naming    &Nbsp;                enable  COMMAND  enable specified internal commands
  • 2 External Command lookup order

    The      command is found on the system, in essence, to find the command program under a path. The path of the system lookup is saved through the path variable in     linux. After the found program file is properly executed, The file path that it finds is saved to the hash table. The         hash table, which is used to cache the command path that has been executed successfully, is saved to a specific memory space .          Related Variables:             path variable Save default value (centos6.x)             #  echo  $PATH                 /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin             :/usr/sbin:/usr/bin:/root/bin          Related Commands: which,whereis,hash             which -  Display command full path                  which command            whereis -  Show command path and help document path                  whereis command             hash -  Forget or display the cache information in the hash table                  hash  Listing Hash Table information                 hash -d  COMMAND   Delete cache of specified commands in the hash table                  hash -r  Empty Hash table
  • 3 Command Aliases

    Alias-command alias Create alias Name= ' VALUE ' example: Alias hh= ' echo hhhh ' Unalias-alias Unalias name
  • 4 Find order proofs

    • The order of 4.1 hash and path

      Preparation link:     View whoami path     # which whoami     /usr/bin/whoami     Show current PATH value     # echo  $PATH      /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin     :/usr/bin:/root/bin     Empty Hash Table     # hash -r     # hash    hash: hash table empty Experimental Steps:      execute whoami to save its path to the hash table .     then move the WhoAmI file to another directory in path .     The WhoAmI command is executed again, and if the WhoAmI command is displayed correctly,     the WhoAmI program file is found in path, the lookup order is path takes precedence over hash, and vice versa .     # whoami            root     # hash        hits     command    1    /usr/bin/whoami    # mv /usr/bin/whoami /bin           # whoami                -bash: /usr/bin/whoami: No such file  or directory     cannot be found, proving to be the WhoAmI path found in the hash table. So hash takes precedence over path.
    • 4.2 internal and external order

      Preparation session:     PWD is an internal command     # type pwd    pwd  is a shell builtin    pwd file is located on the path     # which  pwd    /bin/pwd     Empty Hash Table     # hash  -r     hash: hash table empty     disable PWD internal commands, Make it use external commands to perform pwd    # enable -n pwd experimental steps:     Cache the path of the PWD command to the hash table, and then copy the WhoAmI command to the path recorded in the hash, which is named pwd.    , which enables the internal command of the PWD command to execute pwd.      If the result shown is a result of WhoAmI, it is queried from the hash table, otherwise the internal command is queried. Vice versa .    # pwd            show current working directory path     centos6.example.com     # hash    hits    command        1    /bin/pwd    # cp /usr/sbin/whoami /bin/pwd        Copy the Whomai command to/bin and rename it to pwd    cp: overwrite  '/bin/pwd '?  y     # pwd          Show Current user name      root    # enable pwd   enable pwd internal command     #  pwd    /root     results PWD Displays the original information, proving that internal commands take precedence over external commands
    • 4.3 alias and external order

      Preparation: Define an alias with the same name as PWD # alias pwd= ' echo Hello ' enable pwd internal command # Enabling PWD Experiment step: Use the PWD command to view the results. If the output hello, the alias is better than the inner and vice versa. # alias pwd= ' echo Hello ' # enable PWD # pwd Hello results show alias is better than internal command
  • 5 Summary

    The      command is divided into:  internal commands and external commands      commands:  type,enable,hash,which,whereis, alias,unalias     variable:  path (Save command Lookup path, separated by:)      command Query order is:          alias ->  Internal Command  -> hash -> path      Supplemental:          When using aliases, use the command itself temporarily. Implementation Method:             \COMMAND              ' COMMAND '               "COMMAND"             /path/to/command    absolute path to use command              example:                 # alias echo= ' Echo 123 '                 # echo abc                 123 abc                 # \echo  Abc                abc

This article is from the "12064120" blog, please be sure to keep this source http://12074120.blog.51cto.com/12064120/1962290

Command lookup mode for Linux commands

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.