Get a free website with any plan

See how
LINUX AND SSH

Counting lines and identifying files with wc and file

Last updated

IN SHORT

On Flashcloud servers over SSH, run wc -l to count lines in a text file and file to inspect a file's actual contents regardless of its extension. These Linux tools let you check log sizes and verify uncorrupted or renamed files before opening, downloading, or running them on your hosting account.

Run wc -l filename to count lines in a text file, and file filename to find out what kind of file you're actually looking at, regardless of its extension. Both are small, generic Linux tools, but they solve a surprisingly common problem: you have a file on your server and you're not sure how big it is or what it is before you open it, download it, or run something against it.

You'll use these most often over SSH, digging through logs or a codebase on your hosting account. They work the same way whether you're on shared hosting or a VPS, with one difference in where you're allowed to point them, covered below.

Counting lines with wc

wc stands for "word count," but its most useful flag for sysadmin work is -l, for lines:

wc -l access.log

This prints a line count and the filename. Drop the filename and pipe something into it instead, and it counts lines from standard input:

grep "500" error.log | wc -l

That counts how many lines in error.log contain "500," which is a fast way to gauge how many server errors happened without opening the file. The same pattern works for counting matches of anything: failed login attempts, a specific IP address, a PHP notice that's flooding your log.

wc has two other flags worth knowing: -w counts words, -c counts bytes. Combined with no flags at all, wc filename prints all three: lines, words, and bytes, in that order.

Counting lines across multiple files

Pass wc -l a glob and it counts each file separately, then gives you a total:

wc -l *.php

This is handy for a quick sense of file sizes across a directory, for example before a git deploy where you want to know roughly how much changed. It's not a diff tool, but a sudden jump in line count on a file you didn't expect to touch is worth a second look.

Counting log lines by date or time range

Web server and application logs grow continuously, so counting the whole file is often less useful than counting a slice of it. Combine grep for a date pattern with wc -l:

grep "30/Sep/2026" access.log | wc -l

If a log has rotated or grown large, tail and head pair well with wc too: tail -n 10000 access.log | wc -l confirms you grabbed the number of lines you expected before you pipe that same slice into something else.

Identifying files with file

file looks at a file's actual contents, not its extension or name, and reports what it really is:

file mystery.dat

Output looks like mystery.dat: gzip compressed data or mystery.dat: PHP script text. This matters because extensions lie constantly on a shared server: a backup someone renamed by hand, an upload with no extension at all, a .txt that's actually a zip. Before you cat a large unknown file to your terminal, or try to import something as SQL, run file on it first.

file is also the fastest way to confirm a download or upload didn't get corrupted or truncated. If you pulled a database dump and expected ASCII text or gzip compressed data but got empty or data (file's term for "I can't identify this"), the transfer likely failed partway through.

Checking multiple files at once

Like wc, file accepts a glob:

file public_html/*

This is a fast way to sanity-check a directory after an upload or a migration: confirm images are actually images, scripts are actually text, and nothing landed as a broken zero-byte stub.

Where root matters

Neither command needs special permissions to run. What differs between shared hosting and a VPS is which files you're allowed to reach. On shared hosting, your SSH session is scoped to your own account, so you're counting and identifying files under your home directory and public_html/, the same paths you'd reach through an FTP client or the File Manager tool in the portal. On a VPS, you have root, so wc and file can reach anywhere on the filesystem, including other users' files and system logs outside your account. That extra reach is useful for real diagnosis, but it also means a careless glob (file /*) will churn through far more than you meant to check.

If you're trying to track resource usage rather than just line counts, the disk figures on your service's resource usage page give you the account-wide picture that wc and file won't, since they only ever look at what you point them at.

Common questions

How do I count specific errors in my log file?

Pipe grep into wc -l. Running grep "500" error.log | wc -l counts how many lines match that error code without opening the entire file.

How do I know if a file transfer got corrupted?

Run file on the transferred item to inspect its real contents. If the output returns empty or data instead of the expected format like gzip compressed data, the transfer likely failed partway through.

Can I run these commands on files outside my home folder?

Only on a VPS. Root access on a VPS lets you check files across the whole filesystem, whereas shared hosting restricts your SSH session to your own home and public_html directories.

What happens if I run wc without any flags?

It prints the line count, word count, and byte count in that specific order. Pass -l if you only want the line count.

CAN'T FIND IT?

Real humans answer fast.

Hosting with us? Open a ticket and a real person replies - no scripts, no upsells. Still choosing a host? The same team is included with every plan, from day one.