Viewing File Contents
Sometimes you just need to peek at a file's contents — check a configuration value, see the last few lines of a log, or search for a specific piece of text. Opening a full editor for these quick checks wastes time. Terminal commands let you view files instantly.
Displaying Entire Files
The cat command (concatenate) displays a file's complete contents:
For short files, cat works perfectly. For longer files, the output scrolls past quickly — that's where other commands help.
In PowerShell, use Get-Content (or its alias cat):
Get-Content config.txt
cat config.txt
Viewing the Beginning
The head command shows the first lines of a file — 10 by default:
The -5 option limits output to 5 lines. Adjust the number as needed.
Get-Content long-file.txt | Select-Object -First 5
Viewing the End
The tail command shows the last lines — essential for checking log files:
tail error.log # Last 10 lines
tail -20 error.log # Last 20 lines
tail -f error.log # Follow: show new lines as they're added
The -f (follow) option is incredibly useful for watching logs in real-time. Press Ctrl+C to stop following.
Get-Content error.log | Select-Object -Last 10
Get-Content error.log -Wait # Follow mode
Searching Within Files
The grep command finds lines containing specific text:
Useful options:
-i— Case-insensitive search-n— Show line numbers-r— Search recursively in folders
Select-String "error" application.log
Select-String "error" *.log # Search multiple files
Combining Commands
These commands become even more powerful when combined. You can pipe (|) output from one command into another:
cat large-file.txt | grep "important" | head -5
This displays the first 5 lines containing "important" from a large file.