LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 01-15-2016, 02:57 PM   #1
fanoflq
Member
 
Registered: Nov 2015
Posts: 235

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

Questions:
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, 03:50 PM   #2
Tonus
Member
 
Registered: Jan 2007
Location: Paris, France
Distribution: Slackware-current with grub2
Posts: 385
Blog Entries: 3

Rep: Reputation: 97
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, 04:19 PM   #3
fanoflq
Member
 
Registered: Nov 2015
Posts: 235

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, 04:29 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,599

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
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 04:34 PM.
 
1 members found this post helpful.
  


Reply


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 12:31 PM
LXer: Linux command Types (Internal and External) LXer Syndicated Linux News 0 08-03-2011 03:50 AM
error: new types may not be defined in a return type Kenny_Strawn Programming 4 10-13-2010 01:21 AM
[SOLVED] Conflicting type declarations between sys/types.h and linux/types.h Da Shi Cao Programming 3 09-14-2010 12:55 AM
Learning Linux command kizersouzay Linux - Newbie 4 07-30-2005 05:38 AM


All times are GMT -5. The time now is 09:05 PM.

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