The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 02-02-2008
Kaminski Kaminski is offline
Registered User
 

Join Date: Feb 2008
Posts: 8
file searching...

Hi! i'm trying to do a script (i'm not an expert, as you will see...) to search files in a directory (and its subdirectories). I'd like to have something like this:

mysearch -a arg1 -b arg2 -c arg3 ecc...

I'd like to be able to search for files in different ways: for example, with

my search -n text* -u Eddie

i'd like to have all the files that begin with "text" owned by Eddie.
The options should be:
-n arg1 : search by name
-f arg2 : search by file dimension
-s arg3 : search by string
-d arg4 : search by date
-u arg5 : search by owner
etc.

I wrote these few lines (i'm not sure it's ok ) to manage the options:

#!/bin/bash
if [ $# = 0 ] ; then echo "Message A" ; fi ;
while getopts n:f:s:d:u: c
do
case $c in
n ) search_by_name ;;
f ) search_by_dim ;;
........
* ) echo "Message B"
esac
done

search_by_name, search_by_dim etc. must be replaced with instructions that find files with a certain name etc.

My problem is how to combine the different options? That way i can search files by name or by string but i don't know how to search by name AND by string... I don't know if it's clear...
I know it's a stupid question but as i said i'm not an expert
Any help would be really appreciated!
Thanks!
Reply With Quote
Remove advertisements
!!
Forum Sponsor