RANGEZERO

Learn / Linux Fundamentals / Shell Basics

Reading Files

guidedeasy 30 min · 130 points

First Bit is still up for grabs: be the first to finish this room.

Most of what happens on a Linux system gets written down somewhere: configuration files, logs, reports. Being able to read them quickly is half of system administration and most of security investigation.

This room covers the tools for that: cat and less for whole files, head, tail and wc for the edges and the size, and grep for finding the one line that matters among fifty thousand. The last task gives you a real machine with a very long log to practise on.

CYB//RANGE Live lab

Log in to launch this room's lab.

Task 1 Reading a whole file

cat prints a whole file to the screen:

$ cat notes.txt
Remember: the archive has one folder per month.

That's perfect for short files and useless for long ones: a 50,000-line log flies past faster than you can read. For those, use less, a pager that shows one screen at a time:

$ less app.log

Inside less:

Key Does
Space / Page Down next screen
b / Page Up back a screen
g / G jump to the start / the end
/word then Enter search forwards for "word" (n for the next match)
q quit

less never changes the file, so it's safe to open anything with it.

Which command shows a long file one screen at a time, and lets you scroll back?

Log in or sign up to answer. 5 pts

****

Which key quits less?

Log in or sign up to answer. 5 pts

*

Inside less, which key starts a search forwards?

Log in or sign up to answer. 5 pts

*

Task 2 The start, the end, and the size

Often you only care about the start or the end of a file.

head shows the first 10 lines, and tail the last 10. Use -n to choose how many:

$ head -n 3 app.log
$ tail -n 1 app.log

Logs grow at the bottom, so tail is the one you'll use most. With -f ("follow") it keeps running and prints each new line as it's written, which makes it ideal for watching a service while you test it. Press Ctrl+C to stop.

$ tail -f /var/log/syslog

wc ("word count") tells you how big a file is. With -l it prints only the number of lines:

$ wc -l app.log
50000 app.log

Which option makes tail keep running and print new lines as they are added? (Short or long form.)

Log in or sign up to answer. 10 pts

**

Which command and option print the number of lines in a file?

Log in or sign up to answer. 10 pts

** **

Task 3 Finding lines with grep

grep prints only the lines that contain a word or pattern:

$ grep "database timeout" app.log
2026-09-21 00:14:52 ERROR db        database timeout
...

The options you'll use every day:

Option Does
-i ignore case (error matches ERROR)
-c print just the number of matching lines
-v invert: show the lines that don't match
-n show each match's line number
-r search every file in a folder, and the folders inside it

Combine them freely: grep -ci warn app.log counts the lines containing "warn" in any case, and grep -rn password /etc finds every mention of "password" under /etc along with its file and line number.

Put the search text in quotes when it contains spaces or symbols the shell might interpret, like {, * or $.

Which grep option prints only the number of matching lines? (Short or long form.)

Log in or sign up to answer. 10 pts

**

Which grep option makes the match ignore upper and lower case? (Short or long form.)

Log in or sign up to answer. 10 pts

**

Which grep option shows the lines that do not match? (Short or long form.)

Log in or sign up to answer. 10 pts

**

Task 4 Try it on a real machine

Cara looks after a busy application. Its log for 21 September is in her home folder, along with the logs of 300 web servers.

  1. Press Launch in CybRange at the top of this page, then Open terminal next to box once it's ready. You're logged in as cara.
  2. Don't cat ~/app.log. It's 50,000 lines long. Try wc -l, head, tail and less on it instead.
  3. Use grep to count the errors, then to search all of ~/servers at once for the flag.

How many lines are in ~/app.log?

Log in or sign up to answer. 10 pts

*****

At what time was the first entry in ~/app.log written? (HH:MM:SS)

Log in or sign up to answer. 10 pts

**:**:**

The very last line of ~/app.log says something finished. What finished? (Two words.)

Log in or sign up to answer. 10 pts

******* ******

How many lines in ~/app.log are ERROR lines?

Log in or sign up to answer. 15 pts

****

One of the files in ~/servers contains a flag. What is it?

Log in or sign up to answer. 20 pts

RZ{************************}