The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to prune multiple branches with find? siegfried UNIX for Dummies Questions & Answers 1 04-11-2008 04:52 AM
Multiple conditions in find or ls stmts mavsman UNIX for Dummies Questions & Answers 5 04-01-2008 05:57 PM
Find and replace a string in multiple files pharos467 UNIX for Dummies Questions & Answers 2 11-05-2007 11:47 PM
find and FTP multiple files in Korn Shell lambjam UNIX for Dummies Questions & Answers 2 08-13-2007 11:50 PM
find multiple file types and tar manthasirisha Shell Programming and Scripting 9 03-21-2006 12:37 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-08-2003
nhatch nhatch is offline
Registered User
  
 

Join Date: Aug 2002
Location: London, England
Posts: 85
multiple -name in find

Hi,

Can I have multiple -name options when using find?

I am using -> find . \( ! -name . -prune \) because I only want to search in the directory i'm in, not sub dirs. But i wan the specify the files I do search for.

How can I do this?

It is in part of this string
for file in `find . \( ! -name . -prune \) \
-user cgi \
-mtime +$age \
-exec basename {} \;`

Cheers in advance,
  #2 (permalink)  
Old 04-08-2003
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,123
Here is an example:
Code:
cd /etc
find . \( ! -name . -prune \) \( -name \*passwd\* -o -name \*shadow\* \) -print
  #3 (permalink)  
Old 04-08-2003
nhatch nhatch is offline
Registered User
  
 

Join Date: Aug 2002
Location: London, England
Posts: 85
Hi Perderabo

This is great, I managed it to do what I was wanting from the command line but when I tried to put it into my script I was getting no files returned.

I have taken the liberty to include my script, would you mind checking it over?

Many thanks in advance

HP_UX 11i
Code:
#! /bin/ksh

control=/home/nhatch/CLEAN/clean_cntrl
dates=`date +%d%m%y_%H%M%S`
rmlog=/home/nhatch/CLEAN/removed_$dates.log

echo "Running $0" >> $rmlog
while read line
do
{
        dir=`echo $line | cut -d, -f1`
        age=`echo $line | cut -d, -f2`
        ext=`echo $line | cut -d, -f3`

                echo  "\t Current search dir is $dir" >> $rmlog
                echo $age
                echo $ext

        for file in `find $dir \( ! -name . -prune \) \( -name \*.$ext \) \
                -user cgi \
                -mtime +$age \
                -exec basename {} \;`
        do
        rm $file
        if [ $? -eq 0 ]
        then
                echo "File $file was deleted " >> $rmlog
        else
                echo "File $file was NOT deleted"  >> $rmlog
        fi
        done

}
done < $control
the control file is listed as example, directory/age/extension

/home/nhatch,5,DAT
/home/admin,7,tmp
  #4 (permalink)  
Old 04-08-2003
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,123
Don't use "find $dir" with the -prune trick. You must "cd $dir", then "find .". As it is, you're pruning everything.
  #5 (permalink)  
Old 04-08-2003
nhatch nhatch is offline
Registered User
  
 

Join Date: Aug 2002
Location: London, England
Posts: 85
many thanks. Works fine now.

Have a good day
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:41 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0