#!/bin/bash
#################################################################
#                                                               #
#  Checks current directory and subdirectories for ownership.   #
#  If it finds anything not owned by $USER it lists them.       #
#                                                               #
#  Koentje  (remon@cobrasoft.nl)                                #
#                                                               #
#################################################################

x=0
notuser="."

while read -r line
do

    own=$(echo $line | awk '{print $3}')

    if [ "$own" != "" ]; then
      if [ "$own" != "$USER" ]; then notuser=$notuser"\n$line"; fi
    fi
    x=$((x+1))

done <<< $(ls -lRG)

echo -e "\n\n"
echo -e "Files checked: \e[32m$x\e[m"
echo -e "Not owned by : \e[32m$USER\e[m"
echo "----------------------"
echo -e "\e[31m$notuser\e[m"
echo "----------------------"
echo -e "\n\n"
