Computing.Net > Forums > Unix > Using find -exec and grep possible?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Using find -exec and grep possible?

Reply to Message Icon

Name: lc
Date: November 4, 2003 at 16:48:17 Pacific
OS: Solaris
CPU/Ram: 4x650, 4GB
Comment:

Hi,

I'm trying to use a combination of find -exec and grep with little success.

Basically, I need a script to search for files modified within the last day that match a certain filenaming pattern. I then need to execute a command on these files. The key however is that it needs to be case insensitive.
Eg.
20781 Oct 28 10:29 test1.txt
499 Oct 28 10:29 test2.txt
77 Oct 28 10:29 TEST.txt

Need to be able to find and remove all files modified on Oct 28 with the filename containing "test" (case insensitive) in it. (Assuming today is Oct 29)

This is what I've come up with, but it removes all files in my directory (not just ones matching "test". I suppose this is because grep is only cosmetic, and has not affect on the results of the find command?

find . -mtime -1 -exec rm {} \; | grep -i "test"

Sorry I'm new to unix. Please bare with me.

Thanks in advance.




Sponsored Link
Ads by Google

Response Number 1
Name: Danny Larouche XL2
Date: November 4, 2003 at 22:25:30 Pacific
Reply:

find . -iname "test*.txt" -mtime -1 -exec rm {} \;


0

Response Number 2
Name: lc
Date: November 5, 2003 at 14:04:28 Pacific
Reply:

Thanks. Unforunately I am on Solaris 8, and the find command doesn't have a -iname switch.

Any other suggestions?


0

Response Number 3
Name: Danny Larouche XL2
Date: November 7, 2003 at 05:21:01 Pacific
Reply:

find . -name "test*.txt" -or -name "TEST*" -and -mtime -1 -exec rm {} \;

this one should work


0

Response Number 4
Name: Rytis Sileika
Date: November 13, 2003 at 23:08:24 Pacific
Reply:

This one should be more elegant if you have to deal with things like "tEsT":

find . -name "[Tt][Ee][Ss][Tt]*" -mtime -1 -exec rm {} \;


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Using find -exec and grep possible?

how to find files and move to direc www.computing.net/answers/unix/how-to-find-files-and-move-to-direc/4822.html

find command and tar files www.computing.net/answers/unix/find-command-and-tar-files/5269.html

small script www.computing.net/answers/unix/small-script/6319.html