Thus I created the “summarize” function. It’s a simple script that basically just grabs data using the methods I listed above, and formats them into an easy-to-read summary. Right now, it consists of:
#!/bin/bash
# A command to provide lots of
# info about a file at glance!
FILE=`file $1`
echo "$FILE has `wc -l $1 | cut -d" " -f1` lines." &&
echo -e "\e[1;34mOwned by: \e[0m`ls -l $1 | cut -d" " -f3` | \e[1;34mGroup: \e[0m`ls -l $1 | cut -d" " -f4`" &&
echo -e "\e[1;34mSize: \e[0m`ls -lh $1 | cut -d" " -f5` | \e[1;34mLast updated: \e[0m`ls -lh $1 | cut -d" " -f6`" &&
echo "**********************************"
echo -e "\e[1;34mTop bits: \n \e[0m" &&
head -n 5 $1 | nl -b a &&
echo "" &&
echo -e "\e[1;34mBottom bits: \n \e[0m" &&
nl -b a $1 | tail -n 5
exit 0
One handy thing I learned while writing this was how to display text in chosen colors in bash, using the
1 | echo -e |
syntax. I find this makes it easier for my eye to quickly move to different fields.
You can also add something like this to your .bashrc:
alias summarize='/location/of/script/summarizer.sh'
Example output on a test .txt file (screenshot to show colors. Your base text color will be different):

[EDIT, 07/03/07]: It is also useful to add contextual lines to the head and tail output. This can be done via:
head -n 5 $1 | nl -b a
This prints the first and last five lines, numbered according to the number of lines in the entire file. I find this makes it much easier to immediately see how long the file is. (Additional note: without the "-b a" option, nl will print lines for each textual line, skipping blank ones. I myself would rather the blank lines also be included, as this is standard practice.) Screenshot above has been updated to reflect this new functionality.
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.








