#!/usr/local/bin/bash # # Directory info script # # List files in directory and info about file types # # v0.1, (c) kpn / Kahvipannu.Com RY / pepe@kahvipannu.fi # VER="0.1"; verb=0; dir="."; typ="."; nam="."; function help { echo -e " di.sh v$VER by kpn usage: di.sh [options] available options: -v : verbose mode on (useless but anyways) -h : this help -d : directory to look in (default: .) -n : match pattern in filenames only -t : match pattern in filenames and types example: di.sh -d /home/user -t ASCII looks for all ASCII files in /home/user " exit } function unk { echo -e " Unknown option try: di.sh -h " exit } while getopts "hvd:n:t:" i; do case "$i" in h) help;; v) verb="1";; d) dir="$OPTARG";; t) typ="$OPTARG";; n) nam="$OPTARG";; *) unk;; esac done if [ $verb = 1 ]; then echo -e "Checking if directory $dir exists" echo fi if [ -d $dir ]; then if [ $verb = 1 ]; then echo -e "It exists..." echo else echo -n fi echo else echo -e "ERROR!! '\e[1m$dir\e[0m' does not exist! (or you don't have access to it)" exit fi if [ $verb = 1 ]; then echo -e "Changing into $dir" echo fi cd $dir echo -e "Info about files in: \e[1m$dir\e[0m " if [ $verb = 1 ]; then echo -e "Listing files in $dir and getting information" echo fi ls | grep $nam | xargs file | grep $typ |\ awk '{ printf "\033[1m%s\033[0m\n", $1; $0=substr($0,length($1)+1,length($0)); sub(/^[ \t]+/, "", $0); printf " %s\n\n", $0 }' exit