Interview Prep/Python for DevOps/OS, filesystem, subprocess & CLIs

What does `shutil` give you that `os` does not?

BeginnerConceptOS, filesystem, subprocess & CLIs
Answer

High-level file operations:

  • shutil.copy2(src, dst) copy with metadata; copytree(src, dst, dirs_exist_ok=True).
  • shutil.move, shutil.rmtree(path) (careful).
  • shutil.make_archive("backup", "gztar", root_dir="/etc/app"), unpack_archive.
  • shutil.disk_usage("/") returns total/used/free.
  • shutil.which("kubectl") finds an executable on PATH (check before calling it).
  • shutil.chown(path, user, group).
All Python for DevOps questions Roadmap: Python for automation

More on OS, filesystem, subprocess & CLIs