您的位置:首页 > 运维架构 > Linux

Linux命令的基础知识

2017-12-23 11:05 344 查看

linux分为内部命令和外部命令

内部命令

shell程序为了满足用户正常使用系统而自带的命令,在系统启动时就加载进内存,并且运行时不会创建子进程

外部命令

为了满足系统上各式各样的功能而存在的可执行程序,位于文件系统的某目录下,在系统加载时不会载入内存,但是在运行时会进行缓存,可通过hash命令查看

type命令区分命令类型

内部显示格式

[root@ming ~]# type cd
cd is a shell builtin


外部命令显示格式

[root@ming ~]# type ls
ls is aliased to `ls --color=auto'


命令执行流程

敲入命令输入回车,此处会提请shell命令解释器找到键入命令说对应的可执行程序,先在内部命令中寻找,如果找不到则调用外部命令(外部命令的搜寻路径定义在环境变量path中),都不存在则会提示命令不存在

命令的帮助手册

内部命令

help command

[root@ming ~]# help cd
cd: cd [-L|[-P [-e]]] [dir]
Change the shell working directory.

Change the current directory to DIR.  The default DIR is the value of the
HOME shell variable.


外部命令

man command:使用手册

command –help

info command:显示信息页

hash命令

说明:每当执行一个外部命令时,shell解释器会将搜寻到的外部命令的路径结果会缓存至kv(key-value)存储中,当第二次执行的时候直接从缓存中加载,不会再去path指定的路径下搜寻,可大大加快执行效率

示例:第一列指命中次数,第二列指命令的绝对路径

[root@ming ~]# hash
hits    command
2    /usr/bin/date
1    /usr/bin/man
1    /usr/bin/info


常用选项

-r 清除hash表

-d 清除指定的命令

[root@ming ~]# hash -d date
[root@ming ~]# hash
hits    command
2    /usr/bin/man
1    /usr/bin/info
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息