Skip to main content
ubuntuask.com

Back to all posts

How to View the First N Lines Of A File In Linux?

Published on
3 min read
How to View the First N Lines Of A File In Linux? image

Best Linux Command Line Tools to Buy in May 2026

1 Pixiecube Linux Commands Line Mouse pad - Extended Large Cheat Sheet Mousepad. Shortcuts to Kali/Red Hat/Ubuntu/OpenSUSE/Arch/Debian/Unix Programmer. XXL Non-Slip Gaming Desk mat

Pixiecube Linux Commands Line Mouse pad - Extended Large Cheat Sheet Mousepad. Shortcuts to Kali/Red Hat/Ubuntu/OpenSUSE/Arch/Debian/Unix Programmer. XXL Non-Slip Gaming Desk mat

  • SPACIOUS DESIGN: LARGE 800X300MM PAD FOR WORK AND GAMING VERSATILITY.
  • EFFICIENT COMMAND GUIDE: QUICK REFERENCE FOR LINUX PROS AND BEGINNERS.
  • DURABLE & EASY CARE: NON-SLIP BASE AND EASY-TO-CLEAN FABRIC FOR LONGEVITY.
BUY & SAVE
$20.95
Pixiecube Linux Commands Line Mouse pad - Extended Large Cheat Sheet Mousepad. Shortcuts to Kali/Red Hat/Ubuntu/OpenSUSE/Arch/Debian/Unix Programmer. XXL Non-Slip Gaming Desk mat
2 Kali Linux Bootable USB Flash Drive for PC – Cybersecurity & Ethical Hacking Operating System – Run Live or Install (amd64 + arm64) Full Penetration Testing Toolkit with 600+ Security Tools

Kali Linux Bootable USB Flash Drive for PC – Cybersecurity & Ethical Hacking Operating System – Run Live or Install (amd64 + arm64) Full Penetration Testing Toolkit with 600+ Security Tools

  • DUAL BOOTABLE DRIVE: WORKS WITH LEGACY BIOS & UEFI SYSTEMS.
  • 600+ PRE-INSTALLED TOOLS: ULTIMATE TOOLKIT FOR ETHICAL HACKING.
  • PREMIUM QUALITY: HIGH-SPEED, RELIABLE HARDWARE WITH FAST SUPPORT.
BUY & SAVE
$22.99
Kali Linux Bootable USB Flash Drive for PC – Cybersecurity & Ethical Hacking Operating System – Run Live or Install (amd64 + arm64) Full Penetration Testing Toolkit with 600+ Security Tools
3 EZITSOL 32GB 9-in-1 Linux bootable USB for Ubuntu,Linux Mint,Mx Linux,Zorin OS,Linux Lite,ElementaryOS etc.| Try or Install Linux | Top 9 Linux for Beginners| Boot Repair | multiboot USB

EZITSOL 32GB 9-in-1 Linux bootable USB for Ubuntu,Linux Mint,Mx Linux,Zorin OS,Linux Lite,ElementaryOS etc.| Try or Install Linux | Top 9 Linux for Beginners| Boot Repair | multiboot USB

  • VERSATILE 9-IN-1 LINUX USB FOR ALL YOUR FAVORITE DISTROS!

  • TRY BEFORE YOU INSTALL-SAFE AND HASSLE-FREE LINUX EXPERIENCE!

  • USER-FRIENDLY DISTROS TAILORED FOR BEGINNERS-NO REGRETS!

BUY & SAVE
$19.77 $20.77
Save 5%
EZITSOL 32GB 9-in-1 Linux bootable USB for Ubuntu,Linux Mint,Mx Linux,Zorin OS,Linux Lite,ElementaryOS etc.| Try or Install Linux | Top 9 Linux for Beginners| Boot Repair | multiboot USB
4 Linux: a QuickStudy Laminated Reference Guide (Quick Study Computer)

Linux: a QuickStudy Laminated Reference Guide (Quick Study Computer)

  • COMPACT DESIGN PERFECT FOR EFFICIENT STORAGE AND TRANSPORT.
  • DURABLE CONSTRUCTION ENSURES LONG-LASTING QUALITY AND PERFORMANCE.
  • SLEEK AESTHETICS ENHANCE ANY WORKSPACE OR HOME SETUP.
BUY & SAVE
$6.95
Linux: a QuickStudy Laminated Reference Guide (Quick Study Computer)
5 Linux Stickers 62pcs Work Decals Aesthetic Waterproof Vinyl Pack Stickers for Water Bottle Laptop Phone Skateboard DIY Decorative Supplies Activities Party

Linux Stickers 62pcs Work Decals Aesthetic Waterproof Vinyl Pack Stickers for Water Bottle Laptop Phone Skateboard DIY Decorative Supplies Activities Party

  • UNIQUE, NON-REPETITIVE DESIGNS FOR DIVERSE VISUAL EFFECTS.
  • HIGH-QUALITY, WATERPROOF VINYL ENSURES DURABILITY AND CLARITY.
  • PERFECT FOR GIFTS; IDEAL FOR DECORATING A WIDE RANGE OF ITEMS.
BUY & SAVE
$7.99
Linux Stickers 62pcs Work Decals Aesthetic Waterproof Vinyl Pack Stickers for Water Bottle Laptop Phone Skateboard DIY Decorative Supplies Activities Party
6 STREBITO Electronics Precision Screwdriver Sets 142-Piece with 120 Bits Magnetic Repair Tool Kit for iPhone, MacBook, Computer, Laptop, PC, Tablet, PS4, Xbox, Nintendo, Game Console

STREBITO Electronics Precision Screwdriver Sets 142-Piece with 120 Bits Magnetic Repair Tool Kit for iPhone, MacBook, Computer, Laptop, PC, Tablet, PS4, Xbox, Nintendo, Game Console

  • 120 BITS + 22 ACCESSORIES FOR ANY DIY OR REPAIR PROJECT NEEDS!
  • ERGONOMIC DESIGN WITH MAGNETIC FEATURES FOR EFFORTLESS REPAIRS.
  • PORTABLE STORAGE BAG KEEPS TOOLS ORGANIZED FOR EASY ACCESS.
BUY & SAVE
$27.99 $37.99
Save 26%
STREBITO Electronics Precision Screwdriver Sets 142-Piece with 120 Bits Magnetic Repair Tool Kit for iPhone, MacBook, Computer, Laptop, PC, Tablet, PS4, Xbox, Nintendo, Game Console
7 Linux Command Line Mouse Pad - 31.5" x 11.8" Large Linux Cheat Sheet Desk Mat for Kali/Ubuntu/Red Hat/Debian/OpenSUSE/Centos/Arch/Mint for Programmers, Developers, and IT Professionals

Linux Command Line Mouse Pad - 31.5" x 11.8" Large Linux Cheat Sheet Desk Mat for Kali/Ubuntu/Red Hat/Debian/OpenSUSE/Centos/Arch/Mint for Programmers, Developers, and IT Professionals

  • 200+ LINUX COMMANDS: STREAMLINE YOUR CLI WORK EFFORTLESSLY!

  • FITS ALL KEYBOARDS: SPACIOUS SURFACE FOR ULTIMATE PRODUCTIVITY!

  • DESIGNED FOR PROS: PERFECT FOR CYBERSECURITY & PROGRAMMING TASKS!

BUY & SAVE
$11.29 $12.19
Save 7%
Linux Command Line Mouse Pad - 31.5" x 11.8" Large Linux Cheat Sheet Desk Mat for Kali/Ubuntu/Red Hat/Debian/OpenSUSE/Centos/Arch/Mint for Programmers, Developers, and IT Professionals
8 Linux Commands Mouse Pad – 180+ Commands Desk Mat – Shortcuts for Programmers – XXL Linux Cheat Sheet Mousepad 31.5" x 11.8"

Linux Commands Mouse Pad – 180+ Commands Desk Mat – Shortcuts for Programmers – XXL Linux Cheat Sheet Mousepad 31.5" x 11.8"

  • ESSENTIAL LINUX COMMANDS FOR QUICK ACCESS, BOOSTING PRODUCTIVITY.
  • SPACIOUS DESIGN FITS LAPTOP AND ACCESSORIES, ENHANCING WORKSPACE.
  • DURABLE, NON-SLIP SURFACE WITH HIGH-RES PRINTING FOR LASTING USE.
BUY & SAVE
$13.99
Linux Commands Mouse Pad – 180+ Commands Desk Mat – Shortcuts for Programmers – XXL Linux Cheat Sheet Mousepad 31.5" x 11.8"
+
ONE MORE?

To view the first N lines of a file in Linux, you can use the head command. Here's how you can achieve this:

  1. Open the terminal.
  2. Use the following syntax to view the first N lines of a file: head -n N filename Replace N with the number of lines you want to view, and filename with the actual name of the file you want to read. For example, to view the first 10 lines of a file named "example.txt", you would use: head -n 10 example.txt
  3. After entering the command, the terminal will display the first N lines of the specified file.
  4. If you omit the -n N option, head will by default display the first 10 lines of the file.

That's it! You can now use the head command to view the desired number of lines at the beginning of a file in Linux.

How do I preview the first N lines of a file in Linux?

You can use the head command to preview the first N lines of a file in Linux.

To preview the first 10 lines of a file, you can use the following command:

head -n 10 filename

Replace filename with the actual name of the file you want to preview, and 10 with the number of lines you want to see.

What is the easiest method to view the first N lines of a file in Linux?

The easiest method to view the first N lines of a file in Linux is by using the "head" command with the "-n" option followed by the number of lines you want to display. For example, to view the first 10 lines of a file named "example.txt", you would use the following command:

head -n 10 example.txt

What option can I use with the cat command to display the first N lines of a file in Linux?

To display the first N lines of a file in Linux using the cat command, you would need to combine it with the head command. The head command is used to display the first few lines (default is 10) of a file.

To display the first N lines of a file using cat and head, you can use the following command:

cat file.txt | head -n N

Replace file.txt with the name of your file, and N with the number of lines you want to display. This command will output the first N lines of the file.

What command can I use to show only the first N lines of a file in Linux?

You can use the head command to show only the first N lines of a file in Linux. The syntax is as follows:

head -n N file.txt

Replace N with the number of lines you want to display and file.txt with the name of your file.