Computing.Net > Forums > Unix > shell script help!

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

shell script help!

Reply to Message Icon

Name: mr_b00
Date: April 3, 2003 at 19:56:30 Pacific
OS: red hat linux
CPU/Ram: p4 256rdram
Comment:

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. :)



Sponsored Link
Ads by Google

Response Number 1
Name: Jimbo
Date: April 4, 2003 at 01:30:03 Pacific
Reply:

#! /bin/ksh
function usage { print "\nUSAGE: $0 [dir] [size]\n" ; exit 1
}
[[ $# != 2 ]] && usage

DIR=$1
if [[ ! -d $DIR ]] ; then
print "Invalid directory."
exit 2
fi

## Size in kb
SIZE_CK=$2

find $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


0

Response Number 2
Name: Jimbo
Date: April 4, 2003 at 01:32:48 Pacific
Reply:

Change the 'print' commands to 'echo' commands and it will work in the bash shell on linux.

-jim


0

Response Number 3
Name: mr_b00
Date: April 4, 2003 at 13:36:16 Pacific
Reply:

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... :)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: shell script help!

Shell Scripting Help www.computing.net/answers/unix/shell-scripting-help/5020.html

C Shell script help! www.computing.net/answers/unix/c-shell-script-help/3108.html

c shell script help PLEASE www.computing.net/answers/unix/c-shell-script-help-please/4355.html