I see the script location for the command date for a normal user, it shows

which date

But when I run the same command from root it shows the output /usr/bin/date. Why so ?

  • Cannot reproduce. Which *nix variant - or which GNU/Linux distribution - are you using? – maulinglawns Sep 28 '18 at 15:27

If which date produces different results for root and another user, then it's likely that they have different values for PATH. The normal user has /bin earlier than /usr/bin (or without /usr/bin at all) and root has /usr/bin/ before /bin (or without /bin at all).

You can verify this by running:

echo ${PATH}

as both root and the non-root user.

The PATH variable is a colon-delimited list of directories in which the shell looks for commands when the absolute path isn't provided. The shell will search those directories, left to right, in the order that they're listed. If the shell finds a command in a directory, then it executes it. The which command does a similar walk and reports the first match that it finds.


It depends on the $PATH variable of the user you are currently logged in. If the script is on more than one directories the first found is used, in this case $PATH of root should be something like


and for the user it should be something like


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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