# Linux commands: wc

> Learn how the Linux wc command counts the lines, words, and bytes in a file or piped input, plus using -l, -w, -c, and -m for characters in Unicode text.

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

The `wc` command gives us useful information about a file or input it receives via pipes.

```bash
echo test >> test.txt
wc test.txt
1       1       5 test.txt
```

Example via pipes, we can count the output of running the `ls -al` command:

```bash
ls -al | wc
6      47     284
```

The first column returned is the number of lines. The second is the number of words. The third is the number of bytes.

We can tell it to just count the lines:

```bash
wc -l test.txt
```

or just the words:

```bash
wc -w test.txt
```

or just the bytes:

```bash
wc -c test.txt
```

Bytes in ASCII charsets equate to characters, but with non-ASCII charsets, the number of characters might differ because some characters might take multiple bytes, for example this happens in Unicode.

In this case the `-m` flag will help getting the correct value:

```bash
wc -m test.txt
```

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