# &&

> The `&&` (and) operator in Unix-like systems executes the second command only if the first command succeeds.

## How does && work in bash to chain commands?

The logical operator that runs a second command only if the first one completes successfully. Commonly used to chain dependent commands.

- Topic: Terminal
- Type: command operator

## Example

Wrong:

```bash
cd build; rm -rf ./*
```

Right:

```bash
cd build && rm -rf ./*
```

With `&&`, the delete runs only if `cd` succeeded; with `;` it runs in the current folder even after a failure.

## Common mistakes

- Using `;` so `rm` still runs after a failed `cd`.

## Key points

- Steps that depend on the previous one are chained with `&&`, not `;`.
- `a && b || c` is not used as if/else, since `c` also runs when `b` fails.
- Build and deploy steps are joined so a failed build never deploys.

## Interview questions

### What is the difference between && and ; in bash?

`;` runs the next command no matter what. `&&` runs it only if the previous one exited with status 0.

### What is the difference between && and &?

`&&` chains commands on success. A single `&` runs the command before it in the background.

## Related cards

- [||](https://wonderium.dev/processes/or.md)
- [|](https://wonderium.dev/processes/pipe.md)
- [`cd <path>`](https://wonderium.dev/processes/cd.md)
- [CI / CD](https://wonderium.dev/processes/ci-cd.md)
- [Terminal](https://wonderium.dev/engineering/terminal.md)

---

- Level: [Processes](https://wonderium.dev/processes.md)
- HTML version: https://wonderium.dev/processes/and
- Last updated: 2026-11-25
