You've actually got two questions here — first, why your Popen
construction doesn't work, and second, how to use os.walk
properly. Ned answered the second one, so I'll address the first one: you need to be aware of shell escaping. The \;
is an escaped ;
since normally ;
would be interpreted by Bash as separating two shell commands, and would not be passed to find
. (In some other shells, {}
must also be escaped.)
But with Popen
you don't generally want to use a shell if you can avoid it. So, this should work:
import subprocess
subprocess.Popen(('find', '/tmp/mount', '-type', 'f',
'-name', '*.rpmsave', '-exec', 'rm', '-f', '{}', ';'))