wcx
Print newline, word, and byte counts for each file.
Mirrors GNU wc. Run it as wcx, or as gnux wcx.
Synopsis
wcx [OPTION]... [FILE]...GNU reference
Description
wcx prints the number of lines, words and bytes in each FILE, followed by the file name, and a 'total' line when more than one FILE is given. With no FILE, or when FILE is -, it reads standard input. -l, -w, -m, -c and -L select which counts to print: newlines, words, characters, bytes and the display width of the longest line. Whatever the order of the options, the counts are always printed in the order lines, words, characters, bytes, maximum line length. A word is a run of non-whitespace characters; input is decoded as UTF-8, and bytes that are not valid UTF-8 count toward words and bytes but not characters. --total=WHEN controls the summary line and --files0-from=F reads the file names, NUL-terminated, from F. Columns are right-aligned to a width derived from the files' sizes, as in GNU wc. On a terminal, gnux's terminal view (--pretty=auto, the default) draws the counts as a framed table with a header naming each count (Lines, Words, Chars, Bytes, Longest) and the total below a rule of its own, written once every file is counted; --total=only still prints the bare number. Piped or redirected output is exactly GNU's, and --pretty=never or GNUX_PRETTY=never turns the view off.
Permissions
Needs read permission on each FILE and search permission on the directories leading to it. With -c alone on a regular file only its metadata is consulted, so search permission on the directory is enough. Nothing is ever modified.
Use cases
- Counting the lines of a file or of a pipeline's output with
-l. - Measuring the size of a set of source files, with a total.
- Checking a text against a word or character limit.
- Finding the widest line of a file with
-Lbefore formatting it. - Getting a file's size in bytes cheaply with
-c. - Counting the entries in a directory by piping
lsxinto it. - Getting a single grand total for a large, generated list of files with
--files0-fromand--total=only. - Verifying in a script that a file is not empty, or that output has an expected length.
Flags
-c, --bytes print the byte counts
-m, --chars print the character counts
--files0-from F read input from the files specified by NUL-terminated names in file F; if F is - then read names from standard input
--help display this help and exit
-l, --lines print the newline counts
-L, --max-line-length print the maximum display width
--pretty WHEN[="always"] the gnux terminal view WHEN: 'always' (the default when WHEN is omitted), 'auto' (the default: on a terminal only), or 'never'; GNUX_PRETTY sets the default
--theme NAME color the view with the built-in theme NAME (gnux theme picks and saves one); GNUX_THEME sets the default
--total WHEN when to print a line with total counts; WHEN can be: auto, always, only, never (default "auto")
--version output version information and exit
-w, --words print the word countsExamples
Count lines, words and bytes of a file
wcx README.mdCount only the lines
wcx -l access.logCount the words of an essay
wcx -w essay.txtPrint the size of a file in bytes
wcx -c image.pngCount characters rather than bytes
wcx -m unicode.txtFind the display width of the longest line
wcx -L README.mdPrint lines and words together (always in that order, whatever the flag order)
wcx -wl essay.txtCount the lines of several files, with a total
wcx -l *.goCount several files without the total line, or force it for a single file
wcx -l --total=never *.go && wcx -l --total=always main.goCount the entries a command produces
lsx | wcx -lCount the words of text from standard input
echox 'the quick brown fox' | wcx -wRead the list of files to count from a NUL-separated file
wcx -l --files0-from=sources.lstPrint only the grand total for a list of files found elsewhere
find . -name '*.go' -print0 | wcx -l --files0-from=- --total=onlyFail a script when a file is missing (exit status 1)
wcx -l missing.txt || echox "exit status $?"Count matching files in the portable gnux shell
gnux shell -c 'lsx -1 *.md | wcx -l'Options
Each option has a page of its own, with its usage and examples.
- -c, --bytes: Print the byte counts.
- -m, --chars: Print the character counts.
- --files0-from: Read input from the files specified by NUL-terminated names in file F; if F is - then read names from standard input.
- -l, --lines: Print the newline counts.
- -L, --max-line-length: Print the maximum display width.
- --pretty: The
gnuxterminal view WHEN: 'always' (the default when WHEN is omitted), 'auto' (the default: on a terminal only), or 'never'; GNUX_PRETTY sets the default. - --theme: Color the view with the built-in theme NAME (
gnuxtheme picks and saves one); GNUX_THEME sets the default. - --total: When to print a line with total counts; WHEN can be: auto, always, only, never.
- -w, --words: Print the word counts.
Exit status
| Status | Meaning |
|---|---|
| 0 | success: every operand was processed |
| 1 | failure: an operand could not be processed (diagnosed on standard error), or a command-line mistake |
Help in the terminal
wcx --help # options, first examples, exit status
gnux help wcx # this page: the full manual
gnux help wcx --OPTION # one option in depth, with its examples