Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

4 Answers 4

You can use which command to locate a command:

which file

See man which for more info.

share|improve this answer
    
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 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. –  Radu Rădeanu Apr 13 at 19:27

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
share|improve this answer
    
thanks, it works –  AungThiha Apr 13 at 17:53

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" 
share|improve this answer

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
$
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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