GO KALI FREE
File Management

wc Linux Command

Counts lines, words, and characters in a file.

What does wc do?

Counts lines, words, and characters in a file.

Syntax

wc [options] filename

Practical example

wc -l file.txt

Questions about wc

How do I count lines in a file?

Use `wc -l filename` to count the number of lines. This is one of the most common uses of wc.

How do I count words in a file?

Use `wc -w filename` to count the number of words (whitespace-separated tokens).

How do I count characters in a file?

Use `wc -c filename` to count bytes, or `wc -m filename` to count characters (multi-byte aware).

How do I count lines with a pipe?

Use `command | wc -l` to count output lines. For example, `ls | wc -l` counts files in the current directory.

What does wc output show by default?

By default, wc shows three numbers: line count, word count, and byte count, followed by the filename.

How do I count only specific lines with wc?

Use `grep -c 'pattern' file` to count lines matching a pattern, or `wc -l < file` to count all lines without the filename.

How do I get just the number from wc?

Use `wc -l < file` to get just the number without the filename, or pipe to `awk '{print $1}'`.

How do I count characters in a string?

Use `echo -n 'string' | wc -c` to count characters in a string without the newline.

Related File Management

vim

Opens the powerful Vim text editor for editing files.

ln

Creates links between files. Use -s for symbolic (soft) links.

nano

Opens a simple, beginner-friendly terminal text editor.

stat

Displays detailed file and filesystem information (size, permissions, timestamps).

tail

Displays the last 10 lines of a file. Use -f to follow file changes in real time.

file

Determines and displays the file type (text, binary, image, etc.).