#32 Displaying a File with Additional Information

Many of the most common Unix commands have evolved within slow-throughput, expensive output environments and therefore offer minimal output and interactivity. An example is cat: When used to view a short file, it really doesn't have much helpful output. It would be nice to have more information about the file. This script, a more sophisticated variation of Script #31, accomplishes this.

The Code

 #!/bin/sh # showfile - Shows the contents of a file, including additional useful info. width=72 for input do lines="$(wc -l < $input | sed 's/ //g')" chars="$(wc -c < $input | sed 's/ //g')" owner="$(ls -ld $input | awk '{print $3}')" echo "-----------------------------------------------------------------" ...

Get Wicked Cool Shell Scripts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.