On 10/11/22 22:00, Paulo da Silva wrote:
> 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?

There are certain standards that suggest where to look.  For example,
there's the Linux Filesystem Hiearchy Standard 3.0:
https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s04.html

In short, you want to hard code /bin for a command like rm.  And yes it
will always be in /bin on any standard Linux OS.

Despite modern distros making /bin and /usr/bin the same directory, if
the target OS is anywhere close to the standard, you can always find the
basic commands in /bin.  I would not hard code any script to use
/usr/bin for any basic commands and I would not use anything other than
/bin/sh or /bin/bash as the shell script shebang if you want any sort of
portability.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to