2

so i studied somewhere about the type command and came to know that type command can provide the location of command used with it,more specifically the location of the executable file associated with the command, so i tried the type command with some basic commands like ps,wc,date etc and got their locations but when i used type with ls i got something different

ls is aliased to `ls --color=auto'

but i was expecting for a location.

3

The type command does more than just giving you the location of an executable. Let me cite from the output of help type:

Display information about command type.

For each NAME, indicate how it would be interpreted if used as command name.

That is, the type command tells you, for the given argument, how it would be interpreted by the shell if used as a command. For executables in your path, it will give you their location. But there are other types of commands that are not executables. Among those are bash builtins. For instance, the command cd is a bash builtin:

$ type cd
cd is a shell builtin

In other words, there is no executable called cd. Rather, it is a command directly interpreted by the shell; it is a part of the shell's language. Similarly, the command type is a bash builtin:

$ type type
type is a shell builtin

Another type of commands are aliases. Aliases can be used as convenient user-customizable shortcuts for commands that would otherwise be lengthy to type. You can type alias to see the aliases currently set in your shell. For me, it gives:

$ alias 
alias ll='ls -la'
alias ls='ls --color=auto'

(and a few more that I configured myself, but I skipped them for simplicity)

Therefore, if I type type ls, I get the information that ls is an alias, just as in your case:

$ type ls
ls is aliased to `ls --color=auto'

This is simply because your distribution set this alias somewhere in your user's shell configuration (e.g., in .bashrc if you're using bash). The reason is that this way, the output of the ls command is always colored (it isn't by default). If you would like to find out what ls would mean if this alias was not there, you can simply unalias ls in your current shell session and then use type ls:

$ unalias ls
$ type ls
ls is hashed (/bin/ls)
0

A lot of command shell have an alias for ls set. You could check in your your home directory to the rc file of the shell you use. (for csh that would be .cshrc). The alias is probably in there. If you remove the entry, logout and login again. Then type should give you the info you want.

  • so where can i find a rc file for bash ,can you give me exact location – Noshiii Sep 23 '18 at 19:29
  • 1
    @Noshiii Please note that if you removed that alias, you may not get colored output from the ls command in the future. You may want to revert that change after your experiments. – Malte Skoruppa Sep 23 '18 at 19:48
  • @MalteSkoruppa yes i have done it – Noshiii Sep 23 '18 at 19:53
0

"can provide the location of command used with it,more specifically the location of the executable file associated with the command"

You can also use the which and whereis commands to find the location of executables, if that helps you.

robert@pip2:/tmp$ which ls
/bin/ls

robert@pip2:/tmp$ whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz

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