Solved

Removing certain files from a directory

Posted on 2006-06-28
1
206 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

910 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

19 Experts available now in Live!

Get 1:1 Help Now