Sometimes a command is aliased to itself. For example:

$ type ls
ls is aliased to `ls -al'

How do I invoke type on the ls command itself (and not the alias)?

  • Would recommend which over type if this is for a program and not output purposes – Stan Strum Feb 24 '18 at 23:59
  • @StanStrum Could you elaborate on what "output purposes" mean? Both commands output to stdout as I understand. – flow2k Feb 26 '18 at 8:43
  • 1
    I mean while type gives more information, which tells you where the file is and does not need fancy regex to retrieve the path. (Would use type on the command line, would use which in a program) – Stan Strum Feb 26 '18 at 16:16

From the description of type in man bash:

The -P option forces a PATH search for each name, even if type -t name would not return file. If a command is hashed, -p and -P print the hashed value, which is not necessarily the file that appears first in PATH


$ type ls
ls is aliased to `ls -FG'
$ type -P ls


$ type -a ls
ls is aliased to `ls -FG'
ls is /bin/ls

might be helpful sometimes.

  • 1
    Great - thank you! Although, I think one needs to be careful in using -P, or know what one is doing: $ type cd Result: cd is aliased to 'cd' $ type -P cd Result: /usr/bin/cd. One might mistakenly think the cd command invokes /usr/bin/cd, when it in fact is built-in. In this case, the -a option is handy. – flow2k Feb 24 '18 at 9:36
  • 1
    @flow2k Prefixing a command name with a backslash gives you access to the "real" command, foregoing any alias with that name. So if you had ls aliased to ls -alh and needed the "normal" behaviour, you'd use \ls /path/to/dir or whatever. =) – user101379 Feb 24 '18 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.