Cheatsheets
HomeWriteupsResourcesCheatsheets
Linux
Linux
  • Know Yourself and Your System
    • id
    • logname
    • uname
    • w
    • who
    • whoami
  • Surfing / Knowing Your File System
    • cd
    • df
    • du
    • ls
    • pwd
    • stat
    • tree
  • Knowing About Files / Commands
    • alias
    • file
    • info
    • whatis
    • apropos
    • man
    • help
    • history
    • script
  • Manipulating Files / Directories
    • touch
    • mkdir
    • rm
    • rmdir
    • cp
    • mv
    • ln
  • Interacting with Files
    • cat
    • head
    • less
    • middle
    • more
    • tail
  • STROPS / Text Manipulation
    • awk
    • cut
    • grep
    • jq
    • join
    • paste
    • sed
    • sort
    • tr
    • uniq
    • xargs
    • xclip
    • wc
    • tee
    • echo
    • comm
    • diff
    • patch
    • aspell
    • Combos
  • Formatting the Output
    • nl
    • fold
    • fmt
    • pr
    • printf
  • Searching / Finding
    • find
    • locate
    • which
    • whereis
    • type
  • Web Interaction
    • curl
    • wget
  • xxd
  • References
Powered by GitBook
On this page
  • Introduction
  • Syntax
  • Important Flags
  • Examples

Was this helpful?

  1. Interacting with Files

head

head linux command cheatsheet by Thamizhiniyan C S

Introduction

The head command is used to output the first part of files.


Syntax

head [OPTION]... [FILE]...


Important Flags

Flag
Description

-n num

Prints the first ‘num’ lines instead of the first 10 lines.

-c num

Prints the first ‘num’ bytes from the file specified.

-q

Suppresses printing filenames when more than one file is given.

-v

Prints data from the specified file preceded by its filename.


Examples

Command
Description

To print lines between 10 and 20 in file.txt.

Pipe the output of ls command to head to show only the three most recently modified files or folders.

Pipe the output of ls command to head and sort to display the three most recently used files or folders in alphabetical order.

PreviouscatNextless

Last updated 12 months ago

Was this helpful?

head -n 20 file.txt | tail -10
ls -t | head -n 3
ls -t | head -n 3 | sort