Back to Blog

Zsh Tutorial #4: View & Edit Files (cat, less, head, tail, nano) | macOS Terminal Guide

Sandy LaneSandy Lane

Video: Zsh Tutorial #4: View & Edit Files (cat, less, head, tail, nano) | macOS Terminal Guide by Taught by Celeste AI - AI Coding Coach

Watch full page →

Zsh Tutorial #4: View & Edit Files (cat, less, head, tail, nano) | macOS Terminal Guide

Master essential Zsh commands to view and edit files directly in the macOS Terminal. This guide covers how to display file contents with cat, navigate large files using less, preview file beginnings and ends with head and tail, and edit files using the beginner-friendly nano editor.

Code

# Display entire file contents
cat file.txt

# Display file contents with line numbers
cat -n file.txt

# Concatenate and display multiple files
cat file1.txt file2.txt

# View file interactively with scrolling and searching (press 'q' to quit)
less file.txt

# Show first 10 lines of a file (default)
head file.txt

# Show first 20 lines of a file
head -20 file.txt

# Show last 10 lines of a file (default)
tail file.txt

# Follow a file in real-time (great for logs)
tail -f logfile.txt

# Edit a file with nano text editor
nano file.txt

# Nano shortcuts:
# Ctrl+O to save changes
# Ctrl+X to exit nano

Key Points

  • cat quickly displays entire file contents and can concatenate multiple files.
  • less allows interactive viewing with scrolling and searching, ideal for large files.
  • head and tail show the start or end of files, with options to customize line counts.
  • tail -f is perfect for monitoring real-time updates, such as log files.
  • nano is a simple terminal text editor with easy-to-use keyboard shortcuts for beginners.