Get a free website with any plan

See how
LINUX AND SSH

Reading files with cat, less, head and tail

Last updated

IN SHORT

Flashcloud hosting accounts include standard Linux SSH tools to view files without editing them. Use cat to print short files directly to your screen, less to page through large logs, and head or tail to view the beginning or end. Because these commands only display text, your files remain completely untouched.

Use cat to dump a whole small file to your terminal, less to page through a large one without flooding your screen, and head or tail to peek at just the beginning or end. All four ship on every Linux system, including the SSH shell on Flashcloud hosting, and none of them modify the file, they only display it.

Which one you reach for depends on the file's size and what you're looking for. Config files and small scripts: cat. Log files, big exports, anything you're not sure the size of: less. Checking the last few lines of a log after an error: tail.

cat: dump the whole file

cat stands for "concatenate." It prints a file's full contents to the terminal in one go:

cat public_html/wp-config.php

Fine for anything short: a .htaccess file, a small PHP script, a config file. On a file with thousands of lines, everything scrolls past and only the tail end stays on screen, so cat stops being useful past a certain size. You can also use it to combine files:

cat file1.txt file2.txt > combined.txt

less: page through a large file

less opens a file in a scrollable viewer instead of dumping it all at once:

less error_log

Inside less:

  • Space or Page Down - next page
  • b - previous page
  • /searchterm then Enter - search forward, n to jump to the next match
  • G - jump to the end of the file
  • g - jump back to the start
  • q - quit

less doesn't load the whole file into memory up front, so it stays responsive even on very large logs. It's the right default whenever you're not sure how big a file is. If you've ever used more, less is a strict improvement: it scrolls both directions and supports search.

head and tail: just the ends

head prints the first lines of a file, tail prints the last. Both default to 10 lines:

head access_log
tail error_log

Use -n to change the count:

tail -n 50 error_log

tail is the one you'll reach for most on a live server, because the newest entries in a log file are appended to the end. When you're chasing down a PHP error right after it happened, tail -n 50 error_log gets you straight to the relevant lines without paging through the whole file.

The really useful form is tail -f, which follows a file as it grows and prints new lines as they're written:

tail -f error_log

Leave that running while you reproduce a bug on the site, and you'll watch the error land in real time. Press Ctrl+C to stop following.

Where these apply on Flashcloud hosting

You'll use these commands most often on log files and config files inside your hosting account: error_log in your site's root or a subdirectory, access_log, and files like .htaccess or wp-config.php under public_html. Connect over SSH (see FTP and SFTP accounts for the equivalent file-transfer setup if you need to pull a copy locally instead) and these four commands cover most of what you'd otherwise open File Manager for, once you're comfortable with a terminal.

If a command that worked fine before suddenly returns "Permission denied," it usually means the file belongs to a different user or process. Check Checking your hosting resource usage if you're trying to track down what's filling up disk space, since large log files are a common culprit and less plus tail are exactly the tools for inspecting them before you delete anything.

Common questions

How do I watch an error log in real time?

Run tail -f error_log in your SSH terminal. It prints new lines as they are written so you can watch errors land while reproducing a bug. Press Ctrl+C to stop following.

How do I exit the less screen?

Press q. This quits the viewer and returns you to your command prompt.

Why am I getting a Permission denied error?

The target file belongs to a different user or process. You cannot read its contents under your current account permissions.

Which tool should I use for huge files?

Use less. It does not load the whole file into memory up front, so it stays responsive even on very large logs.

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.