Finding the largest files in a directory.

#!/bin/ksh
#
# Use this script to find the largest files in a particular directory.
#
# Variables:
# $pathname name of the dir. which to search for large files

clear

echo "Enter path which to search: \c"

read pathname

if [ -z $pathname ]
then
echo "Error: pathname cannot be null! Exiting..."
exit
fi

if [ -d $pathname ]
then

clear

echo " "
echo "File Owner File Size File Date File Name"
echo "________________________________________"
echo " "

du -koda "$pathname" | sort -rn | head -50 | awk '{print $2}' | while read file
do
if [ -f $file ]
then
owner=$(ls -als $file | awk '{print $4}')
bsize=$(ls -als $file | awk '{print $6}')
(( fsize = bsize / 1024 /1024 ))
mdate=$(ls -als $file | awk '{print $7" "$8" "$9}')
fpath=$(ls -als $file | awk '{print $10" "$11" "$12}')

echo $owner" "$fsize" Mb "$mdate" "$fpath
fi
done

else

echo " "
echo "Error: '$pathname' - no such directory! Exiting..."
echo " "
exit
fi

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s