![]() |
ssh question - how do I search my server for a bit of text?
I need to search all the files on my entire domain for a bit of text.
I'm still sending traffic to an old sponsor (that doesn't pay) and I can't figure out where it's coming from :1orglaugh I know there's an ssh command I can run - anybody know how to do it? |
I don't know but we keep our sites mirrored on a HD for just such an emergency.
|
cd <to the target directory>
grep -Ri "yourpiece of text here" * :thumbsup |
is there any way to recursively search all directories, say public_html and below?
oh, and say I want to search for foobar - do I use the quotes or no? grep -Ri "foobar" * |
Quote:
say : cd /web/sites/yourdomain.com/public_html then grep -Ri foobar * if its a single word you can drop the quotes *edit* the capital R is recursive .. the lowercase i is case insensitive .. :thumbsup |
so that will search public_html, public_html/directory1, public_html/dirctory1/subdirectory, and all the files in each?
I might be stretching here, but is it possible to do a find and replace with ssh? :D Thanks for the help :) |
oh, and will it find all instances of the text? Like if foobar is surronded with html, or other text - will it find 123foobar123?
|
btw its not an ssh command. its a shell command. thats like calling "http://www.gfy.com" an IE command
remember that ;/ |
Quote:
|
Quote:
|
Quote:
|
ouch - that gave me a ton of results, all mixed up with html!
Can I narrow it down? Say, print a list of files that contain foobar and their locations? |
I'm in a good mood today so i wrote this little perl script for you :
uploaded it and call it test.pl then run it from the command shell: (make sure you're into the public_html dir) perl test.pl Code:
#!/usr/bin/perl |
will that work if I use any text for the replacement?
Here's the thing - I was promoting one sponsor for a long time, and they ended up burning me. To avoid this trouble in the future, I'm now using this instead of an actual hardlink: <?php include('full/path/to/sponsor.php'); ?> where sponsor.php is simply a file with one line in it - my current affiliiate link. So I am effectively replacing this: <a href="http:juicybucks.com/owesme3k/andwontpay.php">link text</a> with this: <a href="<?php include('full/path/to/sponsor.php'); ?>">link text</a> I'm assuming it will work fine, but just to be sure and to get an extra dig into the deadbeat fucks that inspired this thread :winkwink: |
Code:
my $lSearch = quotemeta ("<a href=\"http//:juicybucks.com/owesme3k/andwontpay.php\">link text</a>"); replace the bogus info ofcoz .. make sure you escape (\) the quotes within your texts like a href=\"http:// |
find / -name 'whatyouwanttosearchfor' -print
replace / with whatever directory you want to search. ---edit oops sorry, this will only find filenames - didn't read that you wanted to search files for text. ehm, transfer your server files to a mac and use spotlight? |
Quote:
|
Quote:
That's the bit I was looking for. Thanks man - and I'll look forward to collecting a few checks from you if you have something I can use. The join page to your program looks nice, I'll put some effort into it. Cheers man! |
Quote:
Hey boldy, I gave it a shot, and it didn't seem to work. It listed every file on my server, but nothing was changed. I followed up a second time with a test - I created your test.pl, with the replacement text as follows: Code:
my $lReplace = "testtesttest"; Any ideas? |
Track it?
|
you can use sed to do a search and replace as well if that perl script isn't working. syntax is as follows:
sed 's|oldtext|newtext|g' -i filename that will search filename for oldtext and replace it with newtext. make sure to escape any single quotes within the containing single quotes as well. for multiple files, as far as i know, you must specify a file extension, but you can use the * symbol to search and replace a bunch. so you will probably want to navigate to the containing directory, then do as follows: sed 's|oldtext|newtext|g' -i *.php of course you can do sed 's|oldtext|newtext|g' -i /otherdirectory/*.php if you want to find and replace a file in another directory. when you first mess around with it, you may only want to check one file and make a backup of it to check the results. sed runs quickly and is very useful. do a 'man sed' command for more info. hope that helps! |
is there a command similar to "grep -iR text *" that will find the files and then create a text file so I know which files they are, and their location? Or perhaps a command that will find the files containing that text but then only list the filenames, rather than the file + the code/text I searched for?
|
All times are GMT -7. The time now is 02:19 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123