Find the path of a shell command

Antoon Pardon antoon.pardon at vub.be
Wed Oct 12 15:09:58 EDT 2022



Op 12/10/2022 om 18:49 schreef Paulo da Silva:
> Às 05:00 de 12/10/22, Paulo da Silva escreveu:
>> Hi!
>>
>> The simple question: How do I find the full path of a shell command 
>> (linux), i.e. how do I obtain the corresponding of, for example,
>> "type rm" in command line?
>>
>> The reason:
>> I have python program that launches a detached rm. It works pretty 
>> well until it is invoked by cron! I suspect that for cron we need to 
>> specify the full path.
>> Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin? 
>> What about other commands?
>>
> Thank you all who have responded so far.
> I think that the the suggestion of searching the PATH env seems the best.

I fear that won't work.

If it doesn't work in cron, that probably means, PATH is not set 
properly in your cron environment. And if PATH is not set properly, 
searching it explicitely won't work either.

If rm works when evoked directly in a cron script but not via a python 
script, you may need to export the PATH in your cron script.

-- 
Antoon Pardon


More information about the Python-list mailing list