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.