# $Copyright:	$
# Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
# Sequent Computer Systems, Inc.   All rights reserved.
#  
# This software is furnished under a license and may be used
# only in accordance with the terms of that license and with the
# inclusion of the above copyright notice.   This software may not
# be provided or otherwise made available to, or used by, any
# other person.  No title to or ownership of the software is
# hereby transferred.
#ident	"$Header: filesize 1.2 89/10/10 $@(#)sadmin:admin/menu/filemgmt/filesize	2.6"
#menu# list the largest files in a particular directory
#help# 
#help#	Filesize prints the names of the largest files in a specific
#help#	directory. If you don't specify how many large file to list,
#help#	10 files will be listed.

trap 'exit 0' 1 2 15
trap "	trap '' 1 2
	rm -f /tmp/$$filesize" 0

flags="-qq -k$$"
deffiles=10	# default number of large files

while true
do
	fsys=`checkre ${flags} -H'
	This is the starting point used to build the list of large files.' \
		-fe "Enter full path name of the directory to search
[?, q]: " \
		'^/.*' 'Directory name must begin with a "/".'`

	if [ -d "${fsys}" ]
	then
		break
	else
		echo "\t${fsys} is not the full path name of a valid directory."
	fi
done

nfiles=`checkre ${flags} -D "${deffiles}" \
		-fe "Enter the number of large files to be included in list
(default ${deffiles} largest) [q]:" \
		'^[0-9]*$' 'Answer contains an illegal character.
	Only numbers are permitted.' \
		'[1-9]' 'Answer must be greater than zero.' \
		'^0*.\{1,3\}$' 'Answer must not be larger than 999.'`


cd ${fsys}

a="`expr 0${nfiles} "*" 10`"
du -a  |
	sort -bnr +0 -1  |
	sed -n 1,0${a}'s:^[0-9]*	\./:ls -ldsu :p'  |
	sh -  |
	grep -v '^ *[0-9][0-9]* d'  |
	sed -n 1,0${nfiles}p  |
	sort -bnr +5 -6 |
	cut -c21-29,37- > /tmp/$$filesize

afiles="`cat /tmp/$$filesize  |  wc -l  |  cut -c5-`"

if [ "${nfiles}" -ne "${afiles}" ]
then
	nfiles=${afiles}
	echo "
	There are only ${nfiles} files in `pwd`."
fi
echo "
The ${nfiles} largest files in" `pwd`:"

       file size   date of
owner (characters) last access  filename
----- ------------ ------------ --------"

cat /tmp/$$filesize
