search
HomeOperation and MaintenanceLinux Operation and MaintenanceBasic command classification of LInux system operation explanation

Basic command classification of LInux system operation explanation

1. The concept of command

  • Execution process of command

    When the system executes an external command for the first time The hash cache table is empty. The system will first search for the command from the PTAH path. After finding it, the path will be added to the Hasa cache. When the command is executed again, it will be executed directly from the hash path. If it exists, it will be executed directly. If it does not exist, it will be executed directly. The search will continue from the path under PATH, and the Hash table can improve the calling rate of the command.

  • Priority of command

    alias -------------------------- ----------------Alias ​​
    builtin-------------------------------- -Internal command
    ˆ ˆhash-------------------------Cache table
    ˆ ˆˆˆˆhash-------------------------- ----Executable program or script (external command)

  • Internal command and external command

    The internal command is the shell’s own
    External commands are installed by default when installing the system, and have corresponding paths in the file system

  • Check whether the command is an internal command or an external commandtype [commnd ]

    [root@centos6 ~]# type cat                  #判断cat命令,外部命令显示文件路径
    cat is /bin/cat
    [root@centos6 ~]# type cd                   #判断cd命令
    cd is a shell builtin

    2. Command alias

    The named alias is only valid in the current process
    If you want it to be permanently valid, it must be defined in the configuration file
    Only for the current user: ~/.bashrc
    Valid for all users: /etc/bashrc

  • View all aliases in the processalias

    [root@centos6 ~]#alias
    alias cp='cp -i'
    alias l.='ls -d .* --color=auto'
    alias ll='ls -l --color=auto'
    alias ls='ls --color=auto'
    ......
  • Define aliasalias NAME="VALUE"

    [root@centos6 ~]#alias aubin=cat
    [root@centos6 ~]#aubin test
    hello world
  • Delete alias

    [root@centos6 ~]#unalias aubin
    [root@centos6 ~]#aubin test
    -bash: aubin: command not found
  • Define the alias that is permanently effective for the current user

    [root@centos6 ~]#vim .bashrc 
    # .bashrc
    # User specific aliases and functions
    alias rm='rm -i'
    alias cp='cp -i'
    alias mv='mv -i'
    alias aubin=cat                                # 
  • Definition The alias that is effective for the specified user

    [root@centos6 ~]#cd ~ li
    [root@centos6 li]#vim .bashrc                 #编辑用户目录下的.bashrc
  • DefinitionAll usersEffective aliases

    [root@centos6 ~]#vim /etc/bashrc
    alias aubin=cat                                # <hr><h1 id="Internal-commands">3. Internal commands</h1>

The shell program finds the executable program or code corresponding to the typed command. After analysis by the shell, it is submitted to the kernel to allocate resources and run it.

  • View all internal commands

    [root@centos6 ~]#help
    [root@centos6 ~]#enable
    enable .
    enable :
    enable [
    enable alias
    enable bg
    enable bind
    ......
  • Disable and enable internal commandsenable

    [root@centos6 li]#enable -n cd                 #禁用内部命令
    [root@centos6 li]#enable cd                    #启用内部命令
  • Disable internal commandsInvalid

    [root@centos6 li]#enable -n pwd
    [root@centos6 li]#enable -n                    #查看禁用的内部命令或如下图用help
    enable -n pwd

    You can also check the disabled commands byhelp*# before the command ##Represents that the command has been used】
    黄色方框 中命令前的*代表命令已禁用Disables the internal command
    enable -n pwd can still be used

    [root@centos6 li]#pwd
    /home/li
    Use

    which to view the command The executable file

    [root@centos6 li]#which pwd
    /bin/pwd
    When the internal command is disabled, continue to search the Hash table and

    \(PATH. Until the /bin/pwd# is found in \)PATH according to the bash priority. ##'s executable file will run it.

  • View disabled internal commands
  • [root@centos6 li]#enable -n
    enable -n cd
    enable -n pwd

    Or use the

    help

    command as shown above

4.HASH cache table

is used to display and clear the hash table. When executing the command, the system will first query the hash table.

    View the command cache
  • hash

    <pre class="brush:php;toolbar:false">[root@centos6 ~]# hash   hits  command    3    /usr/bin/cal    1    /usr/bin/yum</pre> <pre class="brush:php;toolbar:false">[root@centos6 ~]# 查看详细的Hash表 [root@centos6 ~]#hash -l builtin hash -p /bin/dd dd builtin hash -p /usr/bin/yum yum</pre>

  • Add content to the Hash table
  • hash - p path command

    <pre class="brush:php;toolbar:false">[root@centos6 ~]#将cat定义一个别名存在hash表 [root@centos6 ~]#hash -p /bin/cat aubin   [root@centos6 ~]#aubin test hello world</pre>

  • Print the path of the command in the Hash table
  • hash -t command

    <pre class="brush:php;toolbar:false">[root@centos6 ~]#hash -t aubin /bin/cat</pre>

  • Delete Specify the command in the Hash table
  • hash -d command

    <pre class="brush:php;toolbar:false">[root@centos6 ~]#hash -d aubin</pre>

  • Delete all commands in the Hash table
  • hash -r

    <pre class="brush:php;toolbar:false">[root@centos6 ~]# hash -r</pre>

  • View the path of the command
  • which

    <pre class="brush:php;toolbar:false">[root@centos6 ~]# which cat            #查看命令的路径,以第一个路径为准 /bin/cat [root@centos6 ~]# which -a cat         #查看命令所有路径,一个命令可能有多个路径 /bin/cat /usr/local/bin/cat</pre>

    5. External command

    The external command is an executable file. When executed When issuing an external command, the system will execute the corresponding executable file in the file directory.

  • List the path of the command
  • [root@centos6 /]#which echo                    #列出命令的路径
    /bin/echo
    [root@centos6 /]#which cp                      #which列出文件路径会显示别名
    alias cp='cp -i'
        /bin/cp
    [root@centos6 /]#which --skip-alias cp         #列出文件路径而不显示别名
    /bin/cp

  • List all the paths of the command. When multiple bash have the same command, the command has Multiple paths.
  • [root@centos6 /]#which -a echo              
    /bin/echo

  • List the paths to commands and help manuals
  • [root@centos6 /]#whereis echo
    echo: /bin/echo /usr/share/man/man1/echo.1.gz /usr/share/man/man1p/echo.1p.gz

The above is the detailed content of Basic command classification of LInux system operation explanation. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
什么是linux设备节点什么是linux设备节点Apr 18, 2022 pm 08:10 PM

linux设备节点是应用程序和设备驱动程序沟通的一个桥梁;设备节点被创建在“/dev”,是连接内核与用户层的枢纽,相当于硬盘的inode一样的东西,记录了硬件设备的位置和信息。设备节点使用户可以与内核进行硬件的沟通,读写设备以及其他的操作。

Linux中open和fopen的区别有哪些Linux中open和fopen的区别有哪些Apr 29, 2022 pm 06:57 PM

区别:1、open是UNIX系统调用函数,而fopen是ANSIC标准中的C语言库函数;2、open的移植性没fopen好;3、fopen只能操纵普通正规文件,而open可以操作普通文件、网络套接字等;4、open无缓冲,fopen有缓冲。

linux中什么叫端口映射linux中什么叫端口映射May 09, 2022 pm 01:49 PM

端口映射又称端口转发,是指将外部主机的IP地址的端口映射到Intranet中的一台计算机,当用户访问外网IP的这个端口时,服务器自动将请求映射到对应局域网内部的机器上;可以通过使用动态或固定的公共网络IP路由ADSL宽带路由器来实现。

linux中eof是什么linux中eof是什么May 07, 2022 pm 04:26 PM

在linux中,eof是自定义终止符,是“END Of File”的缩写;因为是自定义的终止符,所以eof就不是固定的,可以随意的设置别名,linux中按“ctrl+d”就代表eof,eof一般会配合cat命令用于多行文本输出,指文件末尾。

linux怎么判断pcre是否安装linux怎么判断pcre是否安装May 09, 2022 pm 04:14 PM

在linux中,可以利用“rpm -qa pcre”命令判断pcre是否安装;rpm命令专门用于管理各项套件,使用该命令后,若结果中出现pcre的版本信息,则表示pcre已经安装,若没有出现版本信息,则表示没有安装pcre。

linux怎么查询mac地址linux怎么查询mac地址Apr 24, 2022 pm 08:01 PM

linux查询mac地址的方法:1、打开系统,在桌面中点击鼠标右键,选择“打开终端”;2、在终端中,执行“ifconfig”命令,查看输出结果,在输出信息第四行中紧跟“ether”单词后的字符串就是mac地址。

手机远程linux工具有哪些手机远程linux工具有哪些Apr 29, 2022 pm 05:30 PM

手机远程linux工具有:1、JuiceSSH,是一款功能强大的安卓SSH客户端应用,可直接对linux服务进行管理;2、Termius,可以利用手机来连接Linux服务器;3、Termux,一个强大的远程终端工具;4、向日葵远程控制等等。

linux中rpc是什么意思linux中rpc是什么意思May 07, 2022 pm 04:48 PM

在linux中,rpc是远程过程调用的意思,是Reomote Procedure Call的缩写,特指一种隐藏了过程调用时实际通信细节的IPC方法;linux中通过RPC可以充分利用非共享内存的多处理器环境,提高系统资源的利用率。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function