Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Using find -exec and grep possible?

Original Message
Name: lc
Date: November 4, 2003 at 16:48:17 Pacific
Subject: Using find -exec and grep possible?
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.



Report Offensive Message For Removal


Response Number 1
Name: Danny Larouche XL2
Date: November 4, 2003 at 22:25:30 Pacific
Subject: Using find -exec and grep possible?
Reply: (edit)
find . -iname "test*.txt" -mtime -1 -exec rm {} \;

Report Offensive Follow Up For Removal

Response Number 2
Name: lc
Date: November 5, 2003 at 14:04:28 Pacific
Subject: Using find -exec and grep possible?
Reply: (edit)
Thanks. Unforunately I am on Solaris 8, and the find command doesn't have a -iname switch.

Any other suggestions?


Report Offensive Follow Up For Removal

Response Number 3
Name: Danny Larouche XL2
Date: November 7, 2003 at 05:21:01 Pacific
Subject: Using find -exec and grep possible?
Reply: (edit)
find . -name "test*.txt" -or -name "TEST*" -and -mtime -1 -exec rm {} \;

this one should work


Report Offensive Follow Up For Removal

Response Number 4
Name: Rytis Sileika
Date: November 13, 2003 at 23:08:24 Pacific
Subject: Using find -exec and grep possible?
Reply: (edit)
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 {} \;


Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Using find -exec and grep possible?

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




XP Installed to G?

exessive internet traffic

ZoneAlarm Question. Blocked Connect

Windows Live Messenger Problem

Delete $Uninstall after SP3 updates


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC