Everything you can do in the shell you can do using Python. The two key modules for doing so are:

  • os, which is easy import os os.system(“ls -l -a”)
  • subprocess, which is “best”

      import subprocess
      subprocess.call(["ls"])
      subprocess.call(["ls", "-l"])
      directory_list = subprocess.check_output(["ls", "-l"])
      directory_list = subprocess.os.listdir('.')