LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

wc

Count lines, words, and bytes in files

TLDR

Count lines, words, and bytes
$ wc [file]
copy
Count only lines
$ wc -l [file]
copy
Count only words
$ wc -w [file]
copy
Count only characters
$ wc -m [file]
copy
Count only bytes
$ wc -c [file]
copy
Count lines in command output
$ [command] | wc -l
copy
Count files in a directory
$ ls | wc -l
copy
Count longest line length
$ wc -L [file]
copy

SYNOPSIS

wc [options] [file...]

DESCRIPTION

wc (word count) prints newline, word, and byte counts for each file. With multiple files, it also prints totals. With no files or stdin, it reads standard input.A word is defined as a sequence of non-whitespace characters delimited by whitespace or line boundaries. This matches most intuitive definitions of "word."The default output shows lines, words, and bytes in that order. Options select which counts to display; if none are specified, all three are shown.wc -l is extremely common for counting items in pipelines, such as counting files, matches, or log entries.

PARAMETERS

-l, --lines

Print line count
-w, --words
Print word count
-c, --bytes
Print byte count
-m, --chars
Print character count
-L, --max-line-length
Print length of longest line
--files0-from=F
Read filenames from file F (NUL-terminated)
--total=when
When to print total (auto, always, only, never)

INSTALL

sudo apt install coreutils
copy
sudo dnf install coreutils
copy
sudo pacman -S coreutils
copy
sudo apk add coreutils
copy
sudo zypper install coreutils
copy
brew install coreutils
copy
nix profile install nixpkgs#coreutils
copy

CAVEATS

Byte count (-c) and character count (-m) differ for multi-byte encodings like UTF-8. Use -m for actual character counts.For counting files, ls | wc -l fails if filenames contain newlines. Use find -print0 | wc -l --files0-from=- for robustness.Empty files have 0 lines, 0 words, and 0 bytes. A file with just "hello" (no newline) has 0 lines but 1 word.

SEE ALSO

sort(1), uniq(1), cut(1), awk(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid