You can use the type
command, ex. type abc
. For example, in a bash shell:
$ type while cd ls gcc apt
while is a shell keyword
cd is a shell builtin
ls is aliased to `ls --color=auto'
gcc is /usr/bin/gcc
apt is hashed (/usr/bin/apt)
The plain type
command only shows the first result. If there are multiple versions of abc
in different locations on your PATH
, or abc
is provided as both a shell keyword and an external executable, or to see both the aliased and unaliased versions of a command, you can use type -a
to list all of them ex.:
$ type -a time
time is a shell keyword
time is /usr/bin/time
$ type -a ls
ls is aliased to `ls --color=auto'
ls is /bin/ls
$ type -a datamash
datamash is /usr/local/bin/datamash
datamash is /usr/bin/datamash
In bash, type
itself is a shell builtin. Other shells such as zsh
and ksh
and dash
(which provides /bin/sh
in Ubuntu) provide similar functionality (although dash
doesn't currently provide type -a
). In tcsh
, the nearest equivalent is the builtin which
command - not to be confused with the external which
command - see Why not use “which”? What to use then?
For commands that are identified as external programs (i.e. have a path, like /usr/bin/gcc
) you can use the file
command to find out what sort of program:
$ file /bin/ls /usr/bin/gcc /usr/sbin/adduser
/bin/ls: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=2f15ad836be3339dec0e2e6a3c637e08e48aacbd, for GNU/Linux 3.2.0, stripped
/usr/bin/gcc: symbolic link to gcc-9
/usr/sbin/adduser: Perl script text executable