10.7 xxd and od: Hexdump and Octal Dump for Binary Inspection

Right, so cat and less are great until they aren’t. You try to cat a binary executable, and your terminal immediately starts screaming at you with a combination of beeps, garbled symbols, and the occasional legible string like “/lib64/ld-linux-x86-64.so.2”. It’s a mess. You’ve just angered the TTY gods. This is where our good friends xxd and od come in—they’re your polite, orderly translators for the raw, unfiltered truth of what’s actually in a file, byte by byte.

10.6 strings: Extracting Printable Text from Binary Files

Right, so you’ve got a file. It’s gibberish. Your text editor is having a full-blown existential crisis trying to display it. But you know there’s something human-readable in there—maybe a hardcoded password, a version string, or the secret URL it’s phoning home to. This is where strings becomes your best friend. It’s the digital equivalent of panning for gold in a river of mud. It doesn’t care about file formats, structure, or encoding (well, mostly, we’ll get to that). It just sifts through the bytes and yells out anything that looks like text.

10.5 file: Detecting File Type by Magic Bytes

Right, let’s get our hands dirty. You’ve got a file. It has no extension, or worse, a lying extension like virus.exe.pdf. The file command on your system is about to become your new best friend, and we’re going to understand its secret language: magic bytes. At its core, file doesn’t trust filenames. Filenames are suggestions; the content is the law. It works by peeking at the first few bytes of the file—the so-called “magic bytes” or “magic number”—and comparing them against a massive, gloriously detailed database of known file signatures. This database is typically /usr/share/misc/magic.mgc (a compiled binary version) or its source file, /usr/share/misc/magic. Go ahead, cat it sometime. It’s a beautiful, arcane mess of patterns and incantations.

10.4 tail -f: Following Growing Log Files in Real Time

Alright, let’s talk about one of the most satisfyingly simple yet powerful tools in your arsenal: tail -f. This is the command you run when you need to watch a log file grow in real time, like a live commentary on the chaotic, often nonsensical, performance of your application. It’s the sysadmin’s equivalent of turning on the commentary track for a disaster movie. The Basic Incantation At its heart, it’s brutally simple. You’re telling tail: “Show me the last 10 lines of this file, and then don’t quit. Stick around. Keep showing me whatever new stuff gets appended to it.”

10.3 head and tail: First and Last Lines

Let’s be honest, you don’t always need to read the whole novel. Sometimes you just want to check the first page to see if it’s the right file, or peek at the ending to see if your massive data processing job finally succeeded. That’s where head and tail come in—the Swiss Army knives for the terminally impatient. They are brutally simple, gloriously fast, and probably on your system already. By default, head will show you the first 10 lines of a file. tail will show you the last 10. It’s the digital equivalent of judging a book by its first and last paragraphs, which, let’s be honest, is a shockingly effective strategy in system administration.

10.2 less and more: Paging Through Long Files

Right, so you’ve got a file. It’s not a little file. It’s a log file, or a massive CSV, or maybe a config file that seems to go on for miles. cat will blast it across your terminal in a blinding, useless waterfall of text. What you need is a pager—a tool that lets you actually read the thing, one screenful at a time. Enter more and less. And yes, less is more. The naming convention is a classic piece of Unix humor that is both brilliant and infuriating. more came first, and then someone built a better version and, with a straight face, called it less because, as the joke goes, “less is more.” I’ll wait while you groan.

10.1 cat: Concatenating and Printing Files

Let’s talk about cat. The name is a stupid, confusing abbreviation for “concatenate,” which is a fancy way of saying “stick things together.” Its primary job is to read files and output their contents sequentially. But let’s be honest: 99% of the time, you and I use it to just quickly dump the contents of a single file to the terminal. We’re not concatenating a thing. We’re just peeking. It’s the digital equivalent of shouting “Hey, what’s in this box?!” and dumping it on the floor.

— joke —

...