AI and the command line

Most AI work happens on Linux servers, reached through a terminal. These are the commands behind it, and the habits that keep you safe when an AI helps you write them.

Why AI runs on Linux

Servers and GPUs

Training and serving models happens on remote Linux machines. You reach them with ssh and check the hardware with nvidia-smi.

Automation

Shell scripts, cron, and tmux keep long jobs running without anyone watching a screen.

APIs return JSON

AI services reply with JSON. curl fetches it and jq picks out the part you need.

A small workflow to try

This sets up an isolated Python environment, then calls a public web API and reads one value from the JSON it returns.

python3 -m venv .venv
source .venv/bin/activate
pip install requests
curl -s https://api.github.com/repos/torvalds/linux | jq '.stargazers_count'

The last line needs jq. Install it with sudo apt install jq.

Using an AI assistant for commands, safely

  1. Read it first. If you cannot explain what each part does, look it up with man or --help.
  2. Be extra careful with deletes and permissions. Commands like rm -r, chmod -R, and chown -R can damage a system quickly, and there is no undo.
  3. Test somewhere safe. Use a throwaway virtual machine or a copy of the files, not the live server.
  4. Keep secrets out of the command. A key typed into a command is saved in your shell history. Read it into a variable with read -s API_KEY instead, and never commit keys to Git.

Command toolbox

git

Download a project and track changes to it. Also the easiest way to deploy a site to a server.

git clone https://github.com/user/siteDB.git

jq

Read and filter JSON in the terminal. AI services return JSON, so this comes up a lot.

curl -s https://api.github.com/repos/torvalds/linux | jq '.stargazers_count'

man

Open the manual page for a command. Read it before you run something an AI suggested.

man tar

nvidia-smi

Show the status of NVIDIA GPUs: load, memory, and running processes. Useful for AI training jobs.

watch -n 2 nvidia-smi

ollama

Download and run an open-weight language model on your own machine, after Ollama is installed.

ollama run llama3.2

pip

Install Python libraries, including the ones used for machine learning.

pip install requests

python3 -m venv

Create an isolated Python environment so project packages do not collide. Activate it with source .venv/bin/activate.

python3 -m venv .venv && source .venv/bin/activate

tmux

Keep a terminal session alive after you disconnect. Good for long training or download jobs.

tmux new -s training

Heads up: this site's server is a small virtual machine with about 1 GB of memory. It is fine for a website but far too small to run a language model, which is why those run on bigger machines.