The command line stops feeling mysterious the moment you learn three ideas: searching text with grep, chaining commands with pipes, and controlling access with permissions. Each is simple on its own, and together they handle most everyday terminal work.
Searching with grep
grep prints lines that match a pattern. Basic usage:
grep "error" server.log
It gets useful with flags:
grep -i "error" server.log # case-insensitive
grep -n "error" server.log # include line numbers
grep -v "debug" server.log # lines that do NOT match
grep -c "error" server.log # count matches
grep -r "TODO" src/ # search a whole directory tree
Use -r on directories (Git repos: add --exclude-dir=.git to skip the history). For a quick count of how often something appears, grep -c beats scanning by eye.
Chaining with pipes
The pipe character, |, sends one command's output into the next command's input. That is the trick that makes the command line composable.
ls -la | grep "\.md$" # list only markdown files
cat server.log | grep error | wc -l
history | grep "docker"
wc -l counts lines, so the middle example counts error lines. head and tail take the first or last N lines:
grep error server.log | tail -n 20 # last 20 error lines
ps aux | grep nginx | head # find processes, first matches
A useful pattern: a pipeline is read left to right as data flowing through filters. Each command transforms the stream, and the final command consumes it.
File permissions
Every file has an owner, a group, and a set of permissions. ls -l shows them as ten characters:
-rw-r--r-- 1 alice devs 1024 Sep 15 10:00 notes.txt
The first character is the type (- file, d directory, l symlink). The next nine split into three groups of three: owner, group, and everyone else. Each group is read (r), write (w), execute (x). In -rw-r--r-- the owner can read and write, while group and others can only read.
Permissions are also represented as octal numbers, where read is 4, write is 2, and execute is 1. You add them per group: 7 = rwx (4+2+1), 6 = rw, 5 = r-x, 4 = r--.
chmod 755 script.sh # owner rwx, group r-x, others r-x
chmod 644 notes.txt # owner rw, group r, others r
chmod 600 secret.key # owner rw only
chmod 755 is the standard for scripts and executables, 644 for ordinary files, and 600 for anything you want only yourself to read. The same digits set a directory's permissions, where read means list contents and execute means enter it.
To make a file executable outright and then run it:
chmod +x backup.sh
./backup.sh
The ./ says "run this file in the current directory", which the shell refuses to do by default for safety. If ./backup.sh gives you "Permission denied", the file is not executable yet; chmod +x fixes it.
Put them together
A realistic one-liner that searches your config for suspicious values and shows only the first few hits:
grep -r "password" ~/.config | head -n 10
Learn these three pieces and most shell work stops being copy-paste from a tutorial and starts being pattern matching you can do yourself.