Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-15-2016, 01:57 PM   #1
Registered: Nov 2015
Posts: 397

Rep: Reputation: Disabled
Question learning linux command types using: type

$ help type
type: type [-afptP] name [name ...]
Display information about command type.
For each NAME, indicate how it would be interpreted if used as a
command name.

So here are some command types:
$ type type
type is a shell builtin

$ type bash
bash is /bin/bash
$ type ls
ls is aliased to `ls --color=auto'
$ type mkdir
mkdir is hashed (/bin/mkdir)
$ type echo
echo is a shell builtin
$ type ps
ps is /bin/ps

What is the difference of command types between the outputs above?

We have these groupings:
a) bash is /bin/bash, ps is /bin/ps
b) mkdir is hashed (/bin/mkdir)
c) echo is a shell builtin
c) ls is aliased to `ls --color=auto'

What are the differences amongst the command types?
Note: I understand what alias is.

As an example, why is mkdir called a hashed command, and
bash or ps is just shown as a /path/filename,
and echo is called a shell builtin.

I also thought bash is a shell.
So the output of type command is confusing to me.....
Thank you.
Old 01-15-2016, 02:50 PM   #2
Registered: Jan 2007
Location: Paris, France
Distribution: Slackware-current
Posts: 516
Blog Entries: 3

Rep: Reputation: 139Reputation: 139
learning linux command types using: type

When you have a path, this is a 'standalone' program.
Otherwise it is a command belonging to the shell you're running.
Don't know what hashed means.
1 members found this post helpful.
Old 01-15-2016, 03:19 PM   #3
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
In the case of
$ type ls
ls is aliased to `ls --color=auto'

How do you determine the type of the real ls?
Thank you.
Old 01-15-2016, 03:29 PM   #4
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,843

Rep: Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472
Some command interpreters maintain a hash table of frequently used commands.

This eliminates having to search through a long PATH environment variable to find a corresponding executable for a command.

It can cause some problems when the command is added to a directory in the path, but not where the hash table has it recorded. These interpreters also include a "rehash" command that causes it to make a pass through the directories and identify new entries, and generate a new hash table.

The "type" command allows you to identify what is actually going to be used when a given command is issued. If a command is located in the hash table it lets you know that (useful if you expected a different result in a command).

The way shells interpret commands is also why the "." is normally excluded from the search path as a security hazard. You really don't want someone elses command to be picked when you really wanted the one you always use...

Last edited by jpollard; 01-15-2016 at 03:34 PM.
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux command to convert, modify or change mime types of files rm_-rf_windows Programming 5 10-07-2012 11:31 AM
LXer: Linux command Types (Internal and External) LXer Syndicated Linux News 0 08-03-2011 02:50 AM
error: new types may not be defined in a return type Kenny_Strawn Programming 4 10-13-2010 12:21 AM
[SOLVED] Conflicting type declarations between sys/types.h and linux/types.h Da Shi Cao Programming 3 09-13-2010 11:55 PM
Learning Linux command kizersouzay Linux - Newbie 4 07-30-2005 04:38 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:30 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration