0

When we check the file type, we use file command to do it. I guess that file command is a binary. So, I look in bin folder for it, which I didn't find. The question is if it's a binary, where is that binary located?

4 Answers 4

1

You can use which command to locate a command:

which file

See man which for more info.

2
  • As a general rule, type is better since it can also find shell functions and aliases. For (many) more details, see here.
    – terdon
    Apr 13, 2014 at 18:29
  • @terdon IMO this is primarily opinion-based and may depends about the shell where we use them, on how do we want to use the output, or the exit status, a.o. If we look at man which and at help type, we can see that which command will win in this case where the OP was interested about a specific command, not shell functions, aliases, builtins, keywords a.o. Apr 13, 2014 at 19:27
1

In most shells, including bash, you can use the type command to find the location of a command:

$ type file
file is /usr/bin/file
0
0

It's located in /usr/bin/file.

The command below will locate things for you. You can replace file with whatever.

which file

Checking for specific stuff in /usr/bin will show you it's there...

cd /usr/bin; ls -l | grep "file" 
0

The best way to do this is to use the type shell builtin as @FlorianDiesch suggested. The which command can also do it but, among various other problems, it does not deal gracefully with aliases or shell functions.

The shell builtin type (which is available on bash,sh,dash,fish,zsh, ksh and probably others), does not have these problems:

$ type file
file is /usr/bin/file

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

$ type fix_config
fix_config is a function
fix_config () 
{ 
    old="ha";
    new="ba";
    sed -i.bak "17 s/$old/$new/" .config;
    cat .config;
    cp .config.bak .config
}

Compare the above to

$ which file
/usr/bin/file

$ which ls
/bin/ls

$ which fix_config
$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .