Find the path of a shell command
Grant Edwards
grant.b.edwards at gmail.com
Mon Oct 17 13:55:08 EDT 2022
On 2022-10-15, Andreas Eder <a_eder_muc at web.de> wrote:
> On Mi 12 Okt 2022 at 05:00, Paulo da Silva <p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt> wrote:
>
>> 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.
> Why not just use os.unlink ?
Because he's using 'rm' to recursively remove a large directory tree
many levels deep.
One might think that could be done by
os.removedirs(name)
Remove directories recursively. [...]
But it doesn't appear so from the description:
Works like rmdir() except that, if the leaf directory is
successfully removed, removedirs() tries to successively remove
every parent directory mentioned in path until an error is raised
(which is ignored, because it generally means that a parent
directory is not empty). For example, os.removedirs('foo/bar/baz')
will first remove the directory 'foo/bar/baz', and then remove
'foo/bar' and 'foo' if they are empty. Raises OSError if the leaf
directory could not be successfully removed.
More information about the Python-list
mailing list