Skip to content

[New] How To Use The Wc Command #5266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .whitesource
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"scanSettings": {
"baseBranches": []
},
"checkRunSettings": {
"vulnerableCheckRunConclusionLevel": "failure",
"displayMode": "diff"
},
"issueSettings": {
"minSeverityLevel": "LOW",
"issueType": "DEPENDENCY"
}
}
97 changes: 97 additions & 0 deletions docs/guides/quick-answers/linux/how-to-use-wc/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
```bash
---
author:
name: Linode
email: [email protected]
description: 'Learn about the wc command, what it can do and how to use it.'
keywords: ["linux", "terminal", "basics"]
tags: ["quick-answers", "linux"]
license: '[CC BY-ND 4.0](https://creativecommons.org/licenses/by-nd/4.0)'
published: 2022-03-09
modified_by:
name: Linode
title: 'How To Use The Wc Command'
contributor:
name: Jan Slezak
link: https://github.com/scumdestroy
external_resources:
- '[The IEEE and The Open Group - Wc](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/wc.html)'
- '[Man Page for wc](https://man7.org/linux/man-pages/man1/file.1.html)'
- '[Wikipedia Page for File(command)](https://en.wikipedia.org/wiki/Wc_%28Unix%29)'
---
```

Linux's `wc` command counts the words, characters or bytes of any non-binary files it receives. It is a simple command that epitomizes the original Linux ethos of "Focus on one thing and do it well".

### Syntax

Coupled with its simple explanation is an equally simple syntax. The `wc` command can be followed by a file, though when one is not present, it will default to analyzing input that is piped to it (or "reading standard input").

```
wc [OPTIONS] [FILE]
cat *.txt | wc [OPTIONS]
```

## Options

- `-c` or `--bytes` will print byte count

- `-m` or `--chars` will print character count

- `-l` or `--lines` will print newline or row count

- `-w` or `--words` will print word count

- `-L` will print the length of the longest word in characters

### Usage

Output from `wc` is minimal, allowing for simple piping into other command line tools.

```
cat file.txt | wc -l
```

{{< output >}}

315 file.txt

{{< /output >}}

```
wc customers.txt items.txt
```

{{< output >}}

22 22 101 customers.txt
15 19 145 items.txt
37 41 246 total

{{< /output >}}

### Common Usage Examples of `wc`

Counting the number of files and folders in your current directory.

```
ls | wc -l
```

{{< output >}}

22

{{< /output >}}

Comparing the output of an automated daily task against yesterdays data.
```
wc -l today.txt yesterday.txt
```

{{< output >}}

323 today.txt
311 yesterday.txt

{{< /output >}}