Linux常用命令-type

命令

type

描述

Display information about command type
显示命令类型

用法

1
type [-afptP] name [name ...]

选项

1
2
3
4
5
Options:
-a 显示命令的所有位置信息,包括别名配置,命令路径等
-p 显示独立命令的命令路径,如果为builtin或alias命令则输出空
-P 通过PATH路径查找命令的绝对路径
-t 显示命令的类型,内部builtin,别名alias,外部file,保留关键字keyword

注意

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$ type ls
ls is aliased to `ls -p --color=auto'
$ type -a ls
ls is aliased to `ls -p --color=auto'
ls is /usr/bin/ls
$ type -a pwd
pwd is a shell builtin
pwd is /usr/bin/pwd
$ type -a hostname
hostname is /usr/bin/hostname

# 显示命令路径
$ type -p cd
$ type -P cd
/usr/bin/cd
$ type -p pwd hostname systemctl
/usr/bin/hostname
/usr/bin/systemctl
$ type -P pwd hostname systemctl
/usr/bin/pwd
/usr/bin/hostname
/usr/bin/systemctl

# 显示命令类型
$ type -t ls cd hostname if
alias
builtin
file
keyword