Find command and use of wildcards


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find command and use of wildcards
# 1  
Old 01-07-2015
Find command and use of wildcards

greetings,

below is the find command i am using for some filesystem maintenance:

Code:
find /data/Engine \( -type d -name .snapshot -prune -o -type d -wholename "/data/Engine/*/CAE" \
   -prune -o -type d -wholename "/data/Engine/*/CAD" -prune -o -name ".*.case" \)\ 
   -mtime +365 -print0 -fls /data/Engine/deleted_files_$DATE.txt -exec rm -f '{}' \;

as you can see i have a couple of directories i wish to exclude. it works but just a little too good. under /data/Engine are the dirs 0000, 0001, 0002, etc. i DO want to exclude the CAE and CAD dirs directly under /data/Engine/0000|0001|0002 but that's it. for example /data/Engine/0000/CAE and /data/Engine/0000/CAD are to be pruned but not /data/Engine/0000/CFD/CAD. can someone please share with me how to get the asterisk wildcard to act only on the CAD and CAE directories directly under /data/Engine/0000, etc?

hope this made sense, thanks.

Last edited by rbatte1; 01-07-2015 at 01:17 PM.. Reason: Splitting code line to make it more readable
# 2  
Old 01-07-2015
Did you try multiple, different starting paths? Like find /data/Engine/*/CFD /data/Engine/*/CED etc.?
And, looks like you could do a bit more parenthesizing, e.g. -type d \( -name n1 -o -name n2 \) -prune.
# 3  
Old 01-07-2015
i didn't try that as i was hoping there's a way to avoid it since there are over 80 directories under /data/Engine that each have a CFD, CAE and CAD subdir.
# 4  
Old 01-07-2015
Perhaps you need to do a larger search and the use grep -v to exclude patterns, something like:-
Code:
find /data/Engine include all searches, such as age here> | egrep -vf /tmp/exclude-patterns | xargs -n 1 echo rm -f

In the file /tmp/exclude-patterns you could put records such as:-
Code:
^\/data\/Engine\/000[1-2]

Make sure there are no blank lines, or you will match & exclude everything.


Does that give you something to work with? Take out the -n 1 echo to really run it.



Robin
# 5  
Old 01-07-2015
Code:
find /data/Engine \
  \( \
    -type d \( \
      -name .snapshot -prune -o \
      -path "/data/Engine/*/CA[DE]" \
    \) -o \
    -name ".*.case" \
  \) -prune -o \
  -mtime +365 -print0 -fls /data/Engine/deleted_files_$DATE.txt -exec rm -f '{}' \;

I am not sure about the -name ".*.case"; what's your intentention?
# 6  
Old 01-08-2015
sorry for the delay folks. after some more tinkering and experimenting with all suggestions i decided since there was more to prune than i was searching i decided on the following solution:

Code:
DIR=`find /data/Engine -maxdepth 2 -type d -name CAE -prune -o -type d -name CAD -prune -o -type d -name R_D -prune -o -type d -name BM -prune\ 
-o -type d -name Minor_Projects -prune -o -type d -name "VI Projects" -prune -o -type d -name CFD -print`

find $DIR \( -type d -name .snapshot -prune -o -name "*.case" \) -mtime +365 -print0 -fls deleted_files.txt -exec rm -f '{}' \;

this way i ended up with an array called $DIR with all of the directories i wanted to search and cleanup. IE: /data/Engine/0000/CFD /data/Engine/0001/CFD

thanks all for chiming it as it gave me a few other angles to view this task from.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] Wildcards used in find, ls and grep commands

Platforms : Solaris 10 and RHEL 5.6 I always get double quotes , single quotes and asteriks mixed up for find, ls and grep commands. The below commands retrieve the correct results. But , unders stress , I get all these mixed up :mad: .So, i wanted to get a clear picture. Please check if... (7 Replies)
Discussion started by: John K
7 Replies

2. Shell Programming and Scripting

Date with Wildcards in Command

I have the following script (parts from help on this forum, thanks y'all): #!/usr/bin/ksh date '+%m %d %Y' | { read MONTH DAY YEAR DAY=`expr "$DAY" - 1` case "$DAY" in 0) MONTH=`expr "$MONTH" - 1` case "$MONTH" in 0) ... (5 Replies)
Discussion started by: he204035
5 Replies

3. UNIX for Dummies Questions & Answers

Help with rm command with wildcards

Hello everyone. My first time posting here. I have a question that may seem very insignificant to some but is one that I've been trying to address for the past several days (haven't had any luck looking online). I'm trying to clean a directory by removing old files that we no longer need.... (2 Replies)
Discussion started by: galileo1
2 Replies

4. Homework & Coursework Questions

Need help using find or locate with wildcards

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: List all files in ~c12100 directory beginning with "BOZO" that end with either "123" or "456" 2. Relevant... (3 Replies)
Discussion started by: ScarletRavin
3 Replies

5. 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

6. Shell Programming and Scripting

Find string in list with wildcards

I need to add code to a shell script to find out if a string matches any item in a list, where the list can contain a wildcard character. For example, if I have the following list: ok_versions="03-02-4, 04-01-*" Then I want to compare a particular string to see if it matches any item in... (11 Replies)
Discussion started by: Johan III
11 Replies

7. UNIX for Dummies Questions & Answers

how to find a file named vijay in a directory using find command

I need to find whether there is a file named vijay is there or not in folder named "opt" .I tried "ls *|grep vijay" but it showed permission problem. so i need to use find command (6 Replies)
Discussion started by: amirthraj_12
6 Replies

8. Shell Programming and Scripting

Little bit weired : Find files in UNIX w/o using find or where command

Yes , I have to find a file in unix without using any find or where commands.Any pointers for the same would be very helpful as i am beginner in shell scritping and need a solution for the same. Thanks in advance. Regards Jatin Jain (10 Replies)
Discussion started by: jatin.jain
10 Replies

9. Shell Programming and Scripting

using wildcards in this perl command

Hi there, is it possible to use wild cards in this statement ssh $remote_server 'perl -pi -e "s,EXP_SERIAL_19b8be67=\"\",EXP_SERIAL_`hostid`=\"UNKNOWN\"," /var/myfile' This command works fine but the bit in bold (the 8 character hostid) will not always be 19b8be67 so I was hoping I could... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

10. Shell Programming and Scripting

command find returned bash: /usr/bin/find: Argument list too long

Hello, I create a file touch 1201093003 fichcomp and inside a repertory (which hava a lot of files) I want to list all files created before this file : find *.* \! -maxdepth 1 - newer fichcomp but this command returned bash: /usr/bin/find: Argument list too long but i make a filter all... (1 Reply)
Discussion started by: yacsil
1 Replies
Login or Register to Ask a Question