>_cmd.script

Beginner Linux · 35 min

Reading and finding

Inspect file contents and quickly search for the text or files you need.

Learn the commands

Commands to know

Everything you need for this lesson is here. Use the full guide only when you want more options and examples.

Print a small file’s contents to the terminal.

Syntax
cat <file>
Example
cat notes/today.txt

Tip: For long files, use less instead so the text does not rush past.

Read a file one screen at a time.

Syntax
less <file>
Example
less /var/log/system.log

Tip: Press q to quit and / to search within the file.

Show the beginning of a file.

Syntax
head [-n lines] <file>
Example
head -n 5 notes.txt

Tip: It shows ten lines by default.

Show the end of a file.

Syntax
tail [-n lines] <file>
Example
tail -n 20 app.log

Tip: Use tail -f app.log to watch new log lines arrive.

Find lines that contain a word or pattern.

Syntax
grep <pattern> <file>
Example
grep -n TODO notes.txt

Tip: Use -n to include matching line numbers.

Search for files and folders by name or condition.

Syntax
find <path> -name <pattern>
Example
find . -name '*.txt'

Tip: Quote wildcard patterns so the shell does not expand them too early.

Try it

Practice exercise

Use grep to find a word in a file, then use find to locate matching files.

Open playground

Your progress

Mark this lesson when you feel ready to move on.

Your progress is saved on this device. Log in to back it up and continue anywhere.

← All Beginner Linux lessons
Reading and finding — Beginner Linux Learning Path | CMD Script