Reading and comparing content: cat, less and diff
You read a configuration file with line numbers, find the start, the end and the errors in a long log, filter with grep, find the difference from a backup with diff and verify integrity with sha256sum; at the end you separate the error lines and count an old compressed log on your own.
Level 101 · 45 min
The order application has been acting strangely since last night. Daniel suspects: "Someone may have touched the settings file. We have yesterday’s backup and a checksum list of the files."
In this lesson you learn the ways to look inside files: cat for short files, head, tail and less for long ones, grep to search, diff to compare and sha256sum to prove whether a file changed.
Analogy: diff is a spot-the-difference game between two pictures; sha256sum takes a file’s fingerprint: change a single letter and the fingerprint changes completely.
What you will do in this lesson
- Read the settings file: cat -n
- The start and end of a long file: head, tail, wc
- Read page by page and search: less
- Filter lines: grep and grep -c
- Compare with the backup: diff
- Put the difference on record: diff -u
- Fingerprints: sha256sum -c
- Separate the error lines
- The old compressed log
- Short quiz
Skills you will earn
- Reading a file with line numbers (cat -n)
- Seeing the start and end of a file (head, tail)
- Counting lines (wc -l)
- Moving around and searching a long file (less)
- Filtering and counting lines (grep, grep -c)
- Reading the difference between two files (diff)
- Saving a difference in the standard format (diff -u)
- Verifying file integrity with digests (sha256sum -c)
- Redirecting output to a file with > and >>
- Reading compressed logs without unpacking (zcat, zgrep)
← File operations: mkdir, cp, mv and rm · Linux quick start · Quick task: find the altered configuration file →
Start for free