Linux administration rests on handling text files: logs, configurations, scripts. This block teaches you to read what a file contains, to find a precise piece of information, to transform text in one command and to edit a file without risk. These are the moves you will use every day.
Why this block exists
A Linux administrator spends most of their time reading and changing files. Without mastering cat, grep, pipes and an editor, you can neither diagnose a problem, nor fix a configuration, nor automate anything.
This block covers five skills:
- read the contents of a file (
cat,less,head,tail); - search for a file, or for a word inside a file (
find,grep); - transform text with pipes and filters (
|,sort,cut,wc); - archive and compress to back up or transfer files;
- edit a file with a command-line editor (nano, vi).
The recommended path
The guides below follow the order in which you need these skills: you read a file before you search it, you search before you transform, and you edit last, once you know what the file contains.
1. Read and search
The guide to read file contents teaches you to choose between cat, less, head and tail depending on the file size and what you are looking for. The one to find files separates two questions that are often mixed up: where the file is, with find and locate, and where the word is inside the file, with grep.
2. Filter and redirect
Filter and transform text combines grep, sort, cut, wc and awk to extract the useful information from a stream. Redirections and pipes connect those commands with |, and send a result to a file with > or >>: the difference between the two is the one that overwrites a file by mistake.
3. Archive
The guide to archive and compress covers tar, gzip and zip, the tools you use to back up a configuration before changing it and to transfer a whole directory from one machine to another as a single file.
4. Edit a file
Nano is the simplest editor, ideal for a quick change when you are starting out. Vi is the universal editor: it is present even on the most minimal systems, where nano is missing, which is why you should at least know how to open, edit and quit it.
Key points
catshows,lesspages,head/tailextract the start or the end: choose according to the size of the file.grepis the most used command in administration: it filters any text stream.- The pipe (
|) chains commands, which is the Unix philosophy: each tool does one thing well. - Nano to start with, Vi when you are on a minimal server: knowing both is essential.