FreeKB - Linux Commands which command
Linux Commands - which command

The which command can be used to determine if some other command line tool exists, and if so, the location of the file. For example, which can be used to determine if the xml_grep command exists.

which xml_grep

 

If the xml_grep command does exist, something like this should be returned, meaning that the xml_grep command is located at /usr/bin/xml_grep.

/usr/bin/xml_grep

 

And the exit code should be 0 (success).

~]# echo $?
0

 

If the xml_grep command does not exist, something like this should be returned.

/usr/bin/which: no xml_grep in (/sbin:/bin:/usr/sbin:/usr/bin)

 

And the exit code should be 1 (failed).

~]# echo $?
1

 

Only the directories in $PATH will be searched. You can echo $PATH to list the directories in $PATH.

~]# echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin

 

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 4781c in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |