DEV Community

POTHURAJU JAYAKRISHNA YADAV
POTHURAJU JAYAKRISHNA YADAV

Posted on

How I Built My Own Linux Command Using Python (Beginner-Friendly, Real-World)

When we start our careers (0–2 years), most of us use commands every day:

df, top, free, kubectl, aws, etc.

But at some point, a thought comes naturally:

“Can I build my own command?”

I had the same question.
This blog is about how I built a simple Linux command using Python, how it actually works under the hood, and how you can do it without memorizing syntax.

This is not a fancy tool, and that’s intentional.

Why build your own command?

Because it teaches you three important things at once:

  • How Linux commands really work
  • How Python packages are structured
  • How real tools get published to PyPI And most importantly, it changes your mindset from:

“I use tools”
to
“I can build tools”

The idea (keep it simple)

I wanted a command that does one small but useful thing:

syscheck

Enter fullscreen mode Exit fullscreen mode
Output:

CPU Usage: 21.4%
Memory Usage: 40.7%
Disk Usage: 16.99%

Enter fullscreen mode Exit fullscreen mode

That’s it.

No dashboards.
No cloud.
Just useful system information, like something you’d quickly run on a server.

First mental model (very important)

Before writing code, understand this:

A Linux command is just an executable file in your PATH.

When you run:

ls

Enter fullscreen mode Exit fullscreen mode

Linux searches directories listed in $PATH and runs the first ls it finds.

Our goal is to:

  • Create a Python program
  • Tell Python: “Expose this as a command”

Project structure (this part matters more than code)

This structure is non-negotiable:

syscheck/
├── pyproject.toml
├── README.md
├── LICENSE
└── syscheck/
    ├── __init__.py
    └── main.py
Enter fullscreen mode Exit fullscreen mode

Why folder inside folder?

Because:

  • Outer syscheck/ → project
  • Inner syscheck/ → Python package

Python only imports packages, not random folders.

This is where most beginners get stuck.

Writing the actual logic (keep it boring)

In syscheck/main.py:

import shutil
import psutil

def main():
    cpu = psutil.cpu_percent(interval=1)
    memory = psutil.virtual_memory().percent
    disk = shutil.disk_usage("/")

    disk_percent = (disk.used / disk.total) * 100

    print(f"CPU Usage: {cpu}%")
    print(f"Memory Usage: {memory}%")
    print(f"Disk Usage: {disk_percent:.2f}%")
Enter fullscreen mode Exit fullscreen mode

Nothing fancy here.

Key idea:

  • Don’t re-invent system logic
  • Use existing libraries (psutil)
  • Focus on clean output

This is how real production tools are written.

Turning Python into a command

This is the most important part.

In pyproject.toml:

[project.scripts]
syscheck = "syscheck.main:main"
Enter fullscreen mode Exit fullscreen mode

Read this in plain English:

Create a command called syscheck.
When someone runs it, call the main() function inside syscheck/main.py.

That’s it.

No magic.
No shell scripting.

Installing it locally (production mindset)

For development:

pip install -e .

Enter fullscreen mode Exit fullscreen mode

For production testing:

pip install .

Enter fullscreen mode Exit fullscreen mode

Once installed, Linux creates this file:

~/.local/bin/syscheck

Enter fullscreen mode Exit fullscreen mode

That file simply calls your Python function.

So when you type:

syscheck

Enter fullscreen mode Exit fullscreen mode

Linux → Python → your code.

Why this matters (career perspective)

At 1–2 years experience, this shows that you:

  • Understand Linux internals
  • Understand Python packaging
  • Think like a tool builder, not just a user

In interviews, I explain it like this:

“I built a small Python-based CLI tool and exposed it as a Linux command using Python’s packaging system.”

That sentence alone creates a strong impression.

Publishing to PyPI (optional but powerful)

Once everything works locally, publishing is just process:

python -m build
twine upload dist/*
Enter fullscreen mode Exit fullscreen mode

After that, anyone can install it with:

pip install syscheck

Enter fullscreen mode Exit fullscreen mode

At that moment, you’re no longer just learning Python —
you’re contributing software.

What I learned from this

  • Commands are simpler than they look
  • Packaging matters more than logic
  • Clean output matters in real tools
  • Understanding beats memorization

Most importantly, I learned that building small things builds confidence.

Final advice to beginners

Don’t try to build:

  • kubectl
  • aws cli
  • monitoring systems

Build small, boring, useful tools.

That’s how real engineers grow.

Top comments (0)