1

I am trying to find files older than certain number of days and remove them

subprocess.call(['find', DIRECTORY, '-mtime', '+5', '-exec', 'rm', '{}', r'\ '])

Why is this call giving me missing argument to -exec error message

1
  • Be careful, your command will delete directories as well as files. Commented May 14, 2013 at 13:26

1 Answer 1

3

While using exec, you need a semicolon to indicate the end of the command.

subprocess.call(['find', DIRECTORY, '-mtime', '+5', '-exec', 'rm', '{}', ';'])
Sign up to request clarification or add additional context in comments.

2 Comments

Or a + if you want to minimize the # of new processes.
@Drt When issuing the command in a shell you need to escape ; to avoid the shell interpreting it as a command separator. Since you aren't invoking a shell script, escaping is not required.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.