When will os.remove fail?

Chris Angelico rosuav at gmail.com
Tue Mar 14 09:56:19 EDT 2017


On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens <jon+usenet at unequivocal.eu> wrote:
> On 2017-03-14, Chris Angelico <rosuav at gmail.com> wrote:
>>> (The bash rm command will ask you before deleting, but Python's os.remove
>>> just removes it.)
>>
>> (And the rm command won't ask if you say "-f".)
>
> rm does not ask before deleting. However some Linux distributions
> take it upon themselves to put "alias rm='rm -i'" in /etc/profile.

I have no such alias, but it still prompts.

'man rm':

       If the -I or --interactive=once option is given,  and  there  are  more
       than  three  files  or  the  -r,  -R, or --recursive are given, then rm
       prompts the user for whether to proceed with the entire operation.   If
       the response is not affirmative, the entire command is aborted.

       Otherwise,  if  a file is unwritable, standard input is a terminal, and
       the -f or --force  option  is  not  given,  or  the  -i  or  --interac‐
       tive=always  option is given, rm prompts the user for whether to remove
       the file.  If the response is not affirmative, the file is skipped.

This is the GNU coreutils rm command. Obviously behaviour may be
different with non-GNU rm's.

ChrisA


More information about the Python-list mailing list