Deleting Multiple Files With the Same Content


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Deleting Multiple Files With the Same Content
# 1  
Old 01-06-2010
Question Deleting Multiple Files With the Same Content

My website has been hacked and i need to remove a lot of unique files with same content. The files have very similar code:

Code:
eval(base64_decode

How do i find multiple/all the files with the above code and remove them?

Thanks.
# 2  
Old 01-06-2010
Code:
sed 's/eval(base64_decode//' urfile  (test with it first, then the next commands)
sed -i 's/eval(base64_decode//' urfile  (if your sed support -i option)
perl -i.bak -pe 's/eval\(base64_decode//' urfile


Last edited by rdcwayx; 01-06-2010 at 10:13 PM..
# 3  
Old 01-06-2010
If the intention is to remove all the files having the given pattern, it could be done as follows:
Code:
find . -type f -name \* -exec grep "eval(base64_decode" {} \; -exec rm {} \;

But if you want to just remove the given pattern from the files in which it occurs, use this:
Code:
find . -type f -name \* -exec sed -i 's/eval(base64_decode/ /g' {} \;


Last edited by Scott; 01-07-2010 at 03:25 AM.. Reason: Please use code tags
# 4  
Old 01-07-2010
Quote:
Originally Posted by sank
If the intention is to remove all the files having the given pattern, it could be done as follows:

find . -type f -name \* -exec grep "eval(base64_decode" {} \; -exec rm {} \;
\;
Can somebody explain how does this part works ?
Code:
grep "eval(base64_decode" {} \; -exec rm {} \;

# 5  
Old 01-07-2010
Quite simple, actually, once you know how it works:

find, by default, connects all predicates and actions with a boolean and. This means that for an action to be run, all previous filters ("it's a file") and actions ("grep for eval(base64_decode") have to be true. grep returns a true status if the search string is found, which allows find to run the rm command on that file.
# 6  
Old 01-07-2010
I know that for conditions it is boolean AND. But now came to know that it is for actions also.

The explanation given was simple & excellent, thanks.
# 7  
Old 01-07-2010
Question How to delete specific files with specific content?

Quote:
Originally Posted by sank
If the intention is to remove all the files having the given pattern, it could be done as follows:
Code:
find . -type f -name \* -exec grep "eval(base64_decode" {} \; -exec rm {} \;

But if you want to just remove the given pattern from the files in which it occurs, use this:
Code:
find . -type f -name \* -exec sed -i 's/eval(base64_decode/ /g' {} \;

Sank, you saved me a lot of headache! Thank you. I have another question:

How do i remove specific files with sepecific content?
For example:

I want to remove all files named readme.html which contain words "Please contact us". How to do that?

Thanks!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Move multiple files 4rm Source to different target folders based on a series num in the file content

Dear Experts my scenario is as follows... I have one source folder "Source" and 2 target folders "Target_123456" & "Target_789101". I have 2 series of files. 123456 series and 789101 series. Each series has got 3 types of fiels "Debit", "Refund", "Claims". All files are getting... (17 Replies)
Discussion started by: phani333
17 Replies

2. Shell Programming and Scripting

Deleting multiple files off an ftp server once they have been downloaded

Hello, I have a server that I have to ftp files off and they all start SGRD and are followed by 6 numbers. SGRD000001 SGRD000002 SGRD000003 The script I have will run every 10 mins to pick up files as new ones will be coming in all the time and what I want to do is delete the files I have... (7 Replies)
Discussion started by: sph90457
7 Replies

3. Shell Programming and Scripting

Create Multiple files with content

I have a file details.csv and I need to create 5 files in same folder named as details1.csv,details2.csv,details3.csv,details4.csv,details5.csv along with contents of details.csv Thanks in Advance. (9 Replies)
Discussion started by: Prashanth B
9 Replies

4. UNIX for Dummies Questions & Answers

problem deleting multiple files using rm in UNIX

I'm baffled..... the system I work on creates files every Mon-Friday I'm trying to delete all files older than 30 days old from a Unix prompt, the command I'm using is: find /directory/ -mtime +30 -exec rm {} \; however it returns /directory/filename: 644 mode ? (y/n) for every file! ... (1 Reply)
Discussion started by: bquattrone
1 Replies

5. Shell Programming and Scripting

Deleting a column in multiple files that are comma separated

Hi, I have a directory that contains say 100 files named sequencially like input_1.25_50_C1.txt input_1.25_50_C2.txt input_1.25_50_C3.txt input_1.25_50_C4.txt .. .. .. input_1.25_50_C100.txt an example of the content in each of the file is: "NAME" "MEM.SHIP" "cgd1_10" "cgd1_10"... (9 Replies)
Discussion started by: Lucky Ali
9 Replies

6. Shell Programming and Scripting

renaming multiple files with first line of content

Hi , I want to rename multiple files with their first line bar the first character + the extension .qual. For the example below the filename should read 7180000000987.qual. I have trawled through different threads for 2 days and I don't seem to find anything I can adopt for this task :confused: ... (7 Replies)
Discussion started by: Bruno
7 Replies

7. Shell Programming and Scripting

deleting lines from multiple text files

I have a directory full of text data files. Unfortunately I need to get rid of the 7th and 8th line from them all so that I can input them into a GIS application. I've used an awk script to do one at a time but due to the sheer number of files I need some kind of loop mechanism to automate... (3 Replies)
Discussion started by: vrms
3 Replies

8. Shell Programming and Scripting

deleting file content

hallo..i work in c-shell and i want to delete the content of a file without deleting the file itself...commands like >filename or echo -n > filename didn't work....thanks in advance (2 Replies)
Discussion started by: tolkki
2 Replies

9. UNIX for Dummies Questions & Answers

Deleting all content in a file from command line

Hey guys, I'd like to delete all text within a text file without actually deleting the file. Is there a vi command I can do from my prompt without actually going into the file and doing a %d i think it is... to remove all the text inside? I want to add this to a cron job to erase all the data... (2 Replies)
Discussion started by: kingdbag
2 Replies

10. Shell Programming and Scripting

deleting multiple files through ftp

Hi, I have a situation where I need to delete multiple files from a folder once I connect to FTP server. I am using ftp script to get the files, number of files always vary from 1 to 100. once I get the files I need to delete all the files downloaded I am making a list of all the files... (4 Replies)
Discussion started by: mgirinath
4 Replies
Login or Register to Ask a Question