# CLI

> The CLI (Command Line Interface) is a text-based interface for interacting with software or hardware by typing commands.

## What is a CLI (command line interface)?

The interface that allows users to interact with a computer or application by typing text commands. Common in system administration and programming tasks.

- Topic: Basics
- Type: software

## Example

Wrong:

```bash
rm -rf $BUILD_DIR/
```

Right:

```bash
rm -rf -- "${BUILD_DIR:?}/"
```

Quotes stop word splitting, and `:?` aborts the command when the variable is empty instead of deleting from the root.

## Common mistakes

- An empty variable turns `rm -rf $DIR/` into `rm -rf /`.
- A path with spaces is split into two arguments because it was not quoted.

## Key points

- Shell variables in commands are quoted, as in `"$DIR"`, so spaces and empty values do not break them.
- Destructive commands like `rm -rf` guard against empty paths, for example with `${DIR:?}`.
- Scripts exit with a non-zero code on failure, for example with `set -e`.

## Interview questions

### Why use a CLI instead of a GUI?

Commands can be repeated, combined with pipes, saved in scripts and run on servers without a screen.

### What is the difference between a CLI and a terminal?

A CLI is any text command interface, including one a program provides. The terminal is the app where you type those commands.

## Related cards

- [Terminal](https://wonderium.dev/engineering/terminal.md)
- [GUI](https://wonderium.dev/engineering/gui.md)
- [|](https://wonderium.dev/processes/pipe.md)
- [`rm <file>`](https://wonderium.dev/processes/rm.md)
- [`npx <package>`](https://wonderium.dev/processes/npx.md)

---

- Level: [Engineering](https://wonderium.dev/engineering.md)
- HTML version: https://wonderium.dev/engineering/cli
- Last updated: 2026-11-25
