?
Solved

Removing certain files from a directory

Posted on 2006-06-28
1
Medium Priority
?
215 Views
Last Modified: 2013-12-27
Hi All,

We run a SunOS 5.8 server.

One directory has about 8000 files, which are all similarly named.
About 1/3 of those files need to be removed.

I need to search inside each file, find a certain phrase/patern and delete those files that contain that phrase.

Is there a script or command that will achieve this.

Please help.

Regards,
Jo
0
Comment
Question by:m0nk3yza
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 38

Accepted Solution

by:
yuzh earned 2000 total points
ID: 17007935
If you are 100% sure that you want to delete file, you can do:

rm `grep -l patern *`

It is safe to create the file list first, then have a look at the list, delete
the file name (if you want to keep the file), then delete the files list
on the list, eg:

grep -l patern * >/tmp/list

after check /tmp/list, and you want to delete the files:

rm `cat /tmp/list`

man grep
to learn more details.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month12 days, 23 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question