# Linux commands: dirname

> Learn how the Linux dirname command returns the directory portion of a path, so dirname /Users/flavio/test.txt gives you back the /Users/flavio folder.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2020-10-16 | Topics: [CLI](https://flaviocopes.com/tags/cli/) | Canonical: https://flaviocopes.com/linux-command-dirname/

Suppose you have a path to a file, for example `/Users/flavio/test.txt`.

Running

```bash
dirname /Users/flavio/test.txt
```

will return the `/Users/flavio` string:

![Terminal showing dirname /Users/flavio/test.txt command output: /Users/flavio](https://flaviocopes.com/images/linux-command-dirname/Screen_Shot_2020-09-10_at_08.31.08.png)

The `dirname` command works on Linux, macOS, WSL, and anywhere you have a UNIX environment
