skip to content
Alvin Lucillo

Using head to view first few lines

/ 1 min read

Suppose we have these 3 scripts, and you just want to check the first line of each script (their shebangs). You can use head and specify the number of lines with -n argument.

tree
.
├── script1.sh
├── script2.sh
└── script3.sh

./* means all files in the current directory. It’s used since head requires files.

head -n 1 ./*
==> ./script1.sh <==
#!/bin/bash

==> ./script2.sh <==
#!/bin/sh

==> ./script3.sh <==
#!/usr/bin/env bash