I want to write a Python script that will automate my commands without waiting for user input.

My python script will delete the least played video. When I execute the command:

rm video_123.mp4

it asks for user input:

rm: remove write-protected regular file 'video_123.mp4'?

to which on giving input y it deletes the file.

How will I write that in python script to automatically delete the file?

  • 1
    Does rm -f video_123.mp4 remove the file without warning ? – Soren A Aug 10 '18 at 12:40
  • 1
    The admin who set up your system probably aliased rm as alias for rm -i. By default rm doesn't prompt for confirmation, only when -i flag is used. Check your ~/.bashrc or /etc/profile – Sergiy Kolodyazhnyy Aug 10 '18 at 12:42
  • Yes. It does. Thank you. But anyways ... what could have been the python script ? – ron123456 Aug 10 '18 at 12:42
  • 1
    -f is of course easier in this case, but you could also use yes | rm video_123.mp4 too. – RoVo Aug 10 '18 at 12:45
  • 1
    @ron123456 In pure Python you'd do os.remove("video_123.mp4") – Timo Aug 11 '18 at 8:05

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.