?
Solved

Removing certain files from a directory

Posted on 2006-06-28
1
Medium Priority
?
218 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 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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

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 …
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
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…
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.:
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

809 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