LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-16-2013, 10:08 AM   #1
ygbarakat@gmail.com
LQ Newbie
 
Registered: Dec 2013
Posts: 2

Rep: Reputation: Disabled
locate all file containing certain text and deleting them all


i need to find a way to find all files containing the string teamviewer and delete them, Im using the Red Hat Linux Centos
 
Old 12-16-2013, 10:24 AM   #2
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora
Posts: 1,687

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
Quote:
Originally Posted by ygbarakat@gmail.com View Post
i need to find a way to find all files containing the string teamviewer and delete them, Im using the Red Hat Linux Centos
Paraphrasing:
Code:
grep <some option> teamviewer $(find -type f /) | xargs rm -f
<some option> is the option that makes grep only print the filename, not the line containing the string. Do a man grep and look it up yourself.
This command is dangerous; it will delete both ASCII and binary files (commands, shared libraries, the kernel file, ....) that contain the string. Only use it if you are certain you don't need these files. Better yet, don't use it; just run the part before the pipe sign and delete them manually.
 
1 members found this post helpful.
Old 12-16-2013, 10:25 AM   #3
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,166

Rep: Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751
Do you mean delete the string or the file?

To delete all files containing the string teamviewer you could try:

(UNTESTED!!!!)
Code:
 grep -Rl teamviewer . | xargs ls -l
to list the files
Code:
 grep -Rl teamviewer . | xargs rm -f
to delete the files
They will look in the current folder and any folder under it.
 
Old 12-16-2013, 10:38 AM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
I suggest you to use a secure way, so you don't delete any other file mistakenly.

First, run following cmd to list out all files containing the string 'teamviewer':
Code:
~$ find /path/to/files -name 'teamviewer*' -print
Then, if you want to delete all those listed files, then invoke:
Code:
~$ find /path/to/files -name 'teamviewer*' -exec rm -rf {} \;
Also, you can use additional option -i with rm cmd, so it will ask you before deleting every file.
Code:
~$ find /path/to/files -name 'teamviewer*' -exec rm -ir {} \;
 
Old 12-16-2013, 12:55 PM   #5
yooden
Member
 
Registered: Dec 2013
Distribution: Debian Wheezy/Jessie # XFCE
Posts: 53

Rep: Reputation: Disabled
Quote:
Originally Posted by shivaa View Post
Also, you can use additional option -i with rm cmd, so it will ask you before deleting every file.
Code:
~$ find /path/to/files -name 'teamviewer*' -exec rm -ir {} \;
Alternatively, use -ok instead of -exec with GNU find(1).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
To locate process which is deleting some specific file dhiraj4mann Linux - Security 8 07-05-2010 12:36 AM
deleting rows in text file in Perl shifter Programming 4 06-28-2010 08:10 PM
Deleting all instances of a certain character from a text file SentralOrigin Linux - Software 6 02-18-2010 02:49 PM
deleting specified lines in a huge text file ruh31 Linux - General 10 06-30-2006 04:34 AM
inserting/deleting characters into a text file ananthbv Programming 7 07-14-2004 12:40 AM


All times are GMT -5. The time now is 06:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration