Solved

Removing certain files from a directory

Posted on 2006-06-28
1
205 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
1 Comment
 
LVL 38

Accepted Solution

by:
yuzh earned 500 total points
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now