Linux命令的执行过程和命令类型

Linux命令一般都是由shell来执行(shell是个程序但在Linux中一切皆文件)shell命令分为内部命令和外部命令,通过type这个命令来查询其他命令是不是内部命令
范例:第二条命令用来查询shell的大小
[root@xia ~]# echo $SHELL /bin/bash [root@xia ~]# ll /bin/bash -rwxr-xr-x. 1 root root 1219248 Nov 9 2019 /bin/bash [root@xia ~]# type echo echo is a shell builtin
外部命令 范例:
[root@xia ~]# type hostname hostname is hashed (/usr/bin/hostname) [root@xia ~]# ll /usr/bin/hostname -rwxr-xr-x. 1 root root 21664 May 11 2019 /usr/bin/hostname
查看命令和切换至外部命令 (第二条直接查看是否有外部命令和内部命令)
[root@xia ~]# type echo echo is a shell builtin [root@xia ~]# type -a echo echo is a shell builtin echo is /usr/bin/echo [root@xia ~]# which echo /usr/bin/echo
查看所有的内部命令:enable
禁用某个内部命令:enable -n [想要禁用的命令名] 使用的时候会使用外部命令
启用某个内部命令:enable [想要禁用的命令名]
查看所有的禁用命令:enable -n
[root@xia ~]# enable -n echo [root@xia ~]# enable -n enable -n echo [root@xia ~]# enable echo [root@xia ~]# enable -n [root@xia ~]#
查看是否为内部命令并查看存放外部命令的文件夹
[root@xia ~]# type hostname hostname is hashed (/usr/bin/hostname) [root@xia ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin [root@xia ~]#
查看内部命令的执行次数例:
[root@xia ~]# hash hits command 1 /usr/bin/tty 5 /usr/bin/hostname 1 /usr/bin/lsblk 2 /usr/bin/cat 2 /usr/bin/ls 1 /usr/sbin/ip
hash缓存:hash -r name 清除名为name的记录
hash -r 清楚所有记录
hash -l 显示hash缓存
alias定义别名 范例:
[root@xia ~]# alias f='free -h' [root@xia ~]# f total used free shared buff/cache available Mem: 1.8Gi 307Mi 989Mi 9.0Mi 503Mi 1.3Gi Swap: 2.0Gi 0B 2.0Gi
命令执行的优先级:别名>内部命令>外部命令 例:(临时)
[root@xia ~]# alias free='free -h' [root@xia ~]# free total used free shared buff/cache available Mem: 1.8Gi 318Mi 977Mi 9.0Mi 504Mi 1.3Gi Swap: 2.0Gi 0B 2.0Gi [root@xia ~]# type free free is aliased to free -h'
持久改:[root@xia ~]# echo "alias free='free -h'" >> .bashrc
删除(临时):[root@xia ~]# unalias free
[root@xia ~]# free
total used free shared buff/cache available
Mem: 1843864 326320 1001200 9324 516344 1348984
Swap: 2097148 0 2097148
`
或用

猜你喜欢

转载自www.cnblogs.com/xiaxiangming/p/13170493.html