0

I am trying to run the following command via my python script, to unzip a bunch of csv.gz files

os.system("find /upload/ -name '*.csv.gz' -print -exec gzip -d {} \") <- Syntax error : EOL while scanning string literal.

#When I try to escape it

os.system("find /upload/ -name '*.csv.gz' -print -exec gzip -d {} \\") <- find: missing parameter for « -exec »

How can I execute find /upload/ -name '*.csv.gz' -print -exec gzip -d {} \ via os.system?

Is there any alternative to os.system("find /upload/ -name '*.csv.gz' -print0 | xargs -0 -n1 gzip -d") I could use?

Imad
  • 2,358
  • 5
  • 26
  • 55

2 Answers2

1

Not using a shell at all is actually a simplification here, as long as you understand what you are doing. You have to add the missing semicolon as already mentioned in the other answer.

import subprocess

subprocess.run([
    'find', '/upload/', '-name', '*.csv.gz', '-print',
    '-exec', 'gzip', '-d', '{}', ';'], check=True)

Maybe see also Running Bash commands in Python

tripleee
  • 175,061
  • 34
  • 275
  • 318
0

You need an (escaped) semicolon:

os.system("find /upload/ -name '*.csv.gz' -print -exec gzip -d {} \\;")

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
Imad
  • 2,358
  • 5
  • 26
  • 55