Table of Contents

Ubuntu - Bash - Scripts - thead

thead prints the first few lines of text files that are located in this the file tree.

The first few lines of a file can provide enough information to identify the contents of the file.

A full list of filenames can be piped to thead.


Usage

thead [dir...]

or

find $HOME/src -name "*.c" -print | sort | thead

Code

#!/bin/bash
#
#  @(#)  thead v1.0 Prints header of files in tree.
 
if [ "`echo $1|cut -c1`" = "-" ]
then  echo "$0: arg error"
       echo "usage: $0 [dir ...]"
       exit 1
fi
 
case $# in
 0)  while read FILE
     do
         if file $FILE | fgrep text >/dev/null 2>&1
           then  echo "\n:::::::::::::::::::::"
                 echo " $FILE"
                 echo "\n:::::::::::::::::::::"
                 head -15 $FILE
         fi
       done;;
  *)  for NAME in $*
      do
             find $NAME -type f -print | sort | wile read FILE
             do
                     if file $FILE | fgrep text >/dev/null 2>&1
                       then  echo "\n:::::::::::::::::::::"
                             echo " $FILE"
                             echo "\n:::::::::::::::::::::"
                             head -15 $FILE
                     fi
             done
      done;;
esac

Example Usage

thead $HOME
find $HOME -name "*.c" -print | sort | thead

Example Usage

thead /etc
thead /usr/include
find $HOME -ctime 0 -print | thead
for NAME in 'who | sed "s/^\([^ ]*\).*/\1/"'
do
done
find $HOME -name "*.c" -print | thead

and

find $HOME -name "*.c" -exec head {} \;