multiple -name in find


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers multiple -name in find
# 1  
Old 04-08-2003
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  
Old 04-08-2003
Here is an example:
Code:
cd /etc
find . \( ! -name . -prune \) \( -name \*passwd\* -o -name \*shadow\* \) -print

# 3  
Old 04-08-2003
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  
Old 04-08-2003
Don't use "find $dir" with the -prune trick. You must "cd $dir", then "find .". As it is, you're pruning everything.
# 5  
Old 04-08-2003
many thanks. Works fine now.

Have a good day Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find command and multiple * usage

Please can i use: find /home/username/public_html/_sub/*/wp-content/*cache* -type f -delete command to empty all folders contianing "cache" in wp-content directory. issue is that in /home/username/public_html/_sub/ i have around 50 folders and i want to use this rule on all of them, so im... (3 Replies)
Discussion started by: postcd
3 Replies

2. Shell Programming and Scripting

FIND w/ multiple expressions

For reference i am still a newb at scripting, but i have what i think is a complex issue. I need to run a FIND on / to identify all files and print them to >> $TEMPFILE I need to avoid MVFS I need to avoid /var/tmp/nastmp/ I was trying find / \( -type d -name nastmp -prune \) -a \( -fstype... (4 Replies)
Discussion started by: nitrobass24
4 Replies

3. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

4. Shell Programming and Scripting

Find multiple string in one file using find command

Hi, I want find multiple string in one file using find coomand. And keeping it in one variable.grep is not working. (5 Replies)
Discussion started by: vivek1489
5 Replies

5. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies

6. Linux

Simplified find command to find multiple file types

Hi, I'm using the following command to find the multiple requierd file types and its working fine find . -name "*.pl" -o -name "*.pm" -o -name "*.sql" -o -name "*.so" -o -name "*.sh" -o -name "*.java" -o -name "*.class" -o -name "*.jar" -o -name "*.gz" -o -name "*.Z" -type f Though... (2 Replies)
Discussion started by: vickramshetty
2 Replies

7. Shell Programming and Scripting

Find multiple patterns on multiple lines and concatenate output

I'm trying to parse COBOL code to combine variables into one string. I have two variable names that get literals moved into them and I'd like to use sed, awk, or similar to find these lines and combine the variables into the final component. These variable names are always VAR1 and VAR2. For... (8 Replies)
Discussion started by: wilg0005
8 Replies

8. Shell Programming and Scripting

find multiple paths

How do i find files in more than one directory? I searched through forums, but could not land into the right thread. I tried something like find dir1|dir2 -name file1 but it doesn't work. Please suggest. (5 Replies)
Discussion started by: krishmaths
5 Replies

9. UNIX for Dummies Questions & Answers

How to prune multiple branches with find?

I wanted to prune multiple branches and only the first one is being pruned. What am I doing wrong? I tried using "-a" instead of "-o" with no luck! Also, is there an easier way to accommodate file names with spaces other than that sed command? Thanks, Siegfried /usr/bin/find . \( -path... (1 Reply)
Discussion started by: siegfried
1 Replies

10. UNIX for Dummies Questions & Answers

Multiple conditions in find or ls stmts

I'm looking for syntax to include two search patterns in a find or ls command. e.g. find BTIME_ACTUAL_HRS* OR BTIME_SCHEDULED_HRS* tia (5 Replies)
Discussion started by: mavsman
5 Replies
Login or Register to Ask a Question