Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

wc

Count lines, words, characters and bytes.

Niveau
RHCSA-examen
Groep
Tekst en zoeken
Root nodig
Nee
Pakket
coreutils

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

wc (word count) prints, for each file: the number of lines, words and bytes. With options you choose one count. wc -l is used all the time to count lines of a file or results of a command.

Zo schrijf je het

wc [OPTION]... [FILE]...
wc [OPTION]... --files0-from=F

Opties 9

Meest gebruikt

-l, --lines
Count lines (new line characters).
-w, --words
Count words (separated by spaces).
-c, --bytes
Count bytes.
-m, --chars
Count characters (different from bytes for UTF-8 text).
-L, --max-line-length
Print the length of the longest line.
--total=when
When to print the total line: auto, always, only, never.
--files0-from=file
Read file names from a file (NUL separated).
--help
Show help.
--version
Show the version.

Voorbeelden 11

$ als gewone gebruiker# als root (of met sudo)

  1. 1Lines, words and bytes

    wc /etc/passwd
      45   95 2512 /etc/passwd

    Three numbers: lines, words, bytes.

  2. 2Count lines only

    wc -l /etc/passwd
    45 /etc/passwd

    Each line is one account.

  3. 3Count results of a command

    ls /etc | wc -l

    How many entries in /etc.

  4. 4Only the number, without the file name

    wc -l < /etc/passwd
    45

    Input from a redirect has no name. Good in scripts.

  5. 5Count running processes

    ps -e --no-headers | wc -l

    How many processes run now.

  6. 6Count failed SSH logins today

    journalctl -u sshd --since today | grep -c "Failed password"

    grep -c counts directly; same as grep … | wc -l.

  7. 7Count lines of all scripts in a folder

    wc -l *.sh

    Each file plus a total line.

  8. 8Check the longest line of a file

    wc -L config.yaml

    Some tools have line length limits.

  9. 9Count characters in UTF-8 text

    echo -n "سلام" | wc -m
    4

    -c would count 8 bytes; -m counts 4 characters.

  10. 10Compare the size of two lists

    wc -l before.txt after.txt

    Quick check after a cleanup or an import.

  11. 11Alert when a log grows too fast

    [ "$(wc -l < /var/log/app/error.log)" -gt 1000 ] && echo "too many errors"

    A tiny monitoring check.

Let op

  • The last line of a file without a new line is not counted by -l.

Tips om te onthouden

  • wc -l = how many lines. wc -l < file = number only.