How to use Python subprocess to run OS commands.

I like using os.system because you can run your favorite Linux commands. The os module has built-in methods, but often they aren’t mapped exactly to Linux’s commands.

For example, show the current working in directory.

In Linux


In Python

import os

Then usually it’s easier to remember this:

import os