Reading files: cat, less, tail
This course covers how the terminal reads files and which command fits each job. It starts with file descriptors, stdin, stdout and stderr, then moves through cat for small files, less for paging and searching, tail for the end of a file and live logs, and head and wc for quick checks. Pipes connect these commands into filters. The last lesson applies the tools to a Rails project, reading the Gemfile, routes, database config and development log to trace a 500 error.
What you'll learn
- ✓How programs open, read and close files through file descriptors
- ✓Printing, numbering, joining and inspecting files with cat
- ✓Paging, searching and jumping to lines with less
- ✓Reading the end of a file and following logs with tail -f
- ✓Quick checks with head and wc, and connecting commands with pipes and grep
- ✓Reading Rails files and logs to trace an error
What is reading a file?
Picture a filing cabinet in an office. To read a document inside it, you do three things: you open the drawer, you read the paper, and you close the drawer. Every program on your computer does the same three steps when it reads a file: open, read, close. This sequence is so fundamental that every…
Read the full lesson free →Curriculum
7 lessonsWhat is reading a file?
Explains the open, read, close cycle, file descriptors, the three standard streams, and why cat exists.
cat: print everything
Covers cat for single and multiple files, line numbers, hidden characters, creating files, and when to avoid it.
less: the interactive reader
Shows how less pages through large files, searches with patterns, jumps to lines, and differs from more.
tail: watch the end
Teaches tail for the last lines of a file, the plus syntax, and following logs live with tail -f.
head & wc: quick inspections
Uses head to read the top of files, combines it with tail, and counts lines, words and bytes with wc.
Pipes: connecting commands
Explains how pipes link stdout to stdin through a kernel buffer, with grep filters and longer pipelines.
Reading files in the Rails world
Applies every tool to a Rails project: inspecting key files, debugging a 500 error, and handling encrypted files.