Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
i need to make a shell script that will take in two parameters: a directory and a size. it'll look somthing like this: filesize [dir] [size]
(*where filesize is the name of the script*)
this script suppose to take the directory and look through it and will display all ordinary file that is larger than the given size or equal to it.
i have a pretty good idea of how to take in input and the parameters but how do i compare the size of the files to the given size? i'm new to unix but i have a good programming background. i just don't know all the shell command that i can use yet. is there an array that i can put the file in the dir into? any help will be appreciated....
btw...i don't need the whole thing done for me...just need to know how i may go about doin this. :)

#! /bin/ksh
function usage { print "\nUSAGE: $0 [dir] [size]\n" ; exit 1
}
[[ $# != 2 ]] && usageDIR=$1
if [[ ! -d $DIR ]] ; then
print "Invalid directory."
exit 2
fi## Size in kb
SIZE_CK=$2find $DIR -type f -ls | while read x x x x x x SIZE x x x NAME ; do
(($SIZE >= $SIZE_CK)) && print "$NAME"
done
-jim

thanks man....this help. i'm really new to doin shell script and learning some of the command is so weird, compare to what i'm used to in regular programming language.
you help alot already but i'm confuse by some of the line that you use....i was wondering if you can explain some of them.
i understand the function usage. i'm unsure what the -d option do? (and it seem that i can't get that line to work. all directory i put in is invalid.) And what goin on with the 'find' line...what with all the xxxxxx... ?
thanks again... :)

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |