Hi everyone. I am fairly new to Linux and I am taking a UNIX course. I have been asked to write a shell script and I am having a little trouble. I was wondering if anyone could help me. Here are my instructions --
create a script called command find_big.sh that recursively finds file equals or exceed X bytes and outputs the names to stdout. The shell shall take 2 arguments: 1 the location to start looking; 2 the size to equal or exceed. Example bash find_big.sh /lib 20000.
---Hint you shell should begin
#!/bin/bash
#validate there are 2 arguments passed
#validate argument 1 exists and display an error if it does not
#validate argument 2 is a number and display error if no
And this is all I've come up with so far.
#!/bin/bash
#validate there are 2 arguments passed
#validate argument 1 exists and display an error if it does not
#validate argument 2 is a number and display error if not
directory=$1
size=$5
ls -l $1 | sort -n -k 5 | awk '{if($5>=size){print $9$5}}'
My if statement in awk is obviously not working. The if statements confuse me some (I have yet to make one work). I think I am trying to make this harder than it is. What I have so far will list any directory sorted by file size, but I'm not sure how to pull our the files that are greater than or equal to my second argument and just list them. I was hoping to make the listing part of this work first then go back and insert the argument validations. I've just gotten myself more confused though. I seem to learn better through reverse engineering for some reason.
If anyone could help, I'd be grateful.
Thanks,
Tim Cummings
tim.cummings@cox.net
Oklahoma City :?: