AI Check for Linux Commands: 5 Proven Steps, 3 Wrong Answers

An AI check, in practice, means verifying what an AI system tells you before you act on it. For people who run Linux systems, the most common case is a command or script suggested by a chatbot. This post shows a repeatable way to check AI-generated commands, using a real test: a small local model answered four everyday Linux questions, and I ran every answer against test data. The lab ran on 20 November 2026 with Ollama 0.40.16 on CPU and the qwen2.5:0.5b model at temperature 0, and the checks ran in Debian 13. A larger model would make fewer mistakes, but the checking method is the same.

The earlier version of this page described "AI check" tools for plagiarism, identity and fraud in general terms. I replaced it with something you can use today.

The test: four questions, four answers

Each prompt asked for "the command only":

  1. List files in /var/log modified in the last 24 hours.
  2. Create logs.tar.gz from /var/log, excluding all *.gz files.
  3. Show listening TCP ports with the process name, using ss.
  4. Print the number of CPU cores.
AI check of generated Linux commands: wrong tar, ss and CPU-count answers compared with real runs
Lab output: three of the four answers were wrong, and ShellCheck flagged only a style issue.

AI check 1: the find command (correct)

find /var/log -type f -mtime -1

The model wrapped it in a paragraph of explanation despite the "command only" instruction, but the command was right. On test files aged 2 hours, 5 hours and 3 days, it listed the two recent ones:

/lab/log/app.log
/lab/log/rotated.1.gz

Even a correct answer needs a check against your own data: -mtime -1 counts in 24-hour units from now, which is what was asked. The details of -mtime rounding are in the find command post.

AI check 2: the tar command (silently wrong)

tar -czf logs.tar.gz /var/log/

The answer ignored the exclusion completely. It runs without any error, which is what makes it dangerous:

$ tar -czf ai.tar.gz log/ && tar -tzf ai.tar.gz
log/
log/app.log
log/old.log
log/rotated.1.gz

The compressed file is in the archive. The correct command adds --exclude:

$ tar -czf fixed.tar.gz --exclude="*.gz" log/ && tar -tzf fixed.tar.gz
log/
log/app.log
log/old.log

Lesson: an AI check is not "does it run". It is "does the result match the requirement". List the archive.

AI check 3: the ss command (wrong flags)

ss -t -n -t -a

-t appears twice, -a shows all sockets instead of listening ones, and there is no -p, so no process name. With a test server on port 8000 it also listed unrelated TIME-WAIT connections and no process column. The right command:

$ ss -tlnp
State  Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0      5            0.0.0.0:8000      0.0.0.0:*    users:(("python3",pid=3226,fd=3))

Check flags against ss --help or the man page; that takes seconds and would have caught it.

AI check 4: counting CPUs (wrong output)

cat /proc/cpuinfo | grep -i "processor" | awk '{print $2}'

It printed a column of colons, one per CPU, because the second field of processor : 0 is the colon. The number the question asked for never appears:

:
:
:

The direct commands agreed with each other:

$ nproc; grep -c ^processor /proc/cpuinfo
20
20

There was one more trap in the lab itself: the container was started with --cpus 2, yet nproc still printed 20. A CPU quota limits how much time a container gets, not how many CPUs it sees. So even the "correct" answer can mislead inside containers; check the cgroup limit (/sys/fs/cgroup/cpu.max) when that matters.

Static analysis is not an AI check

I saved the four answers as a script and ran ShellCheck on it:

In /lab/ai.sh line 5:
cat /proc/cpuinfo | grep -i "processor" | awk '{print $2}'
    ^-----------^ SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.

Its only finding was a style note. A missing --exclude, wrong ss flags and a wrong awk field are all valid shell. Linters catch syntax and quoting problems; they cannot know what you meant. Use them, and still run the commands on test data. For debugging scripts in general, see shell script debugging.

A five-step AI check for commands and scripts

  1. Read the answer against the requirement. Does it address every part (the exclusion, the process name)?
  2. Check each flag in --help or the man page.
  3. Run it on test data whose correct result you know, in a container or a scratch directory, never first on production.
  4. Inspect the result, not the exit code: list the archive, count the lines, read the output.
  5. Lint scripts with ShellCheck as an extra layer, not as the proof.

The same rule applies when an AI agent runs commands for you: limit what its tools may do and log what it did. Tool permissions for agents are covered in AI agent access to tools.

How the test was run

The setup is small enough to repeat on any laptop. Ollama ran in a container, the model was pulled with ollama pull qwen2.5:0.5b, and a short Python script sent each question to the /api/generate endpoint with "temperature": 0 and a fixed seed, so the same question returns the same answer on a rerun. The answers were saved to a file before any checking started, and the check script was written only after reading them. Keeping those two steps separate matters: if you adjust the test to fit the answer, you are no longer checking anything.

A 0.5-billion-parameter model is far weaker than the assistants most people use, and that is the point of using it here: it makes typical mistakes visible in four questions. Stronger models make the same kinds of mistakes less often, which makes them harder to notice, not less important to check.

Beyond commands: what else an AI check should cover

The same habit works for other AI output: verify version numbers and option names in the official documentation, check that a cited URL exists and says what the answer claims, and test configuration snippets with the program's own validator (for example nginx -t, sshd -t or terraform validate). Plausible and correct are different things, and only checking tells them apart.

FAQ

How do I do an AI check on a command before running it?

Check each flag in the man page, run it on test data in a container, and verify the output itself. In the lab, two wrong answers ran with exit code 0.

Can ShellCheck verify AI-generated scripts?

Only partly. It flagged a style issue and missed all three logic errors in this test.

References: Ollama API (the /api/generate call used for the test), the ss(8) and tar(1) manuals.

Comments

Popular posts from this blog

How to Play Minecraft Bedrock Edition on Linux: A Comprehensive Guide for Tech Professionals

Linux desktop frozen? My 5 go-to tricks to try - before forcing a hard reboot

The Ultimate Guide: How to Set Up DXVK in Wine on Linux for Enhanced Gaming Performance