Posts Tagged ‘linux’

recursively search a certain file for certain text (linux)

July 1st, 2009 by Sameer | No Comments | Filed in Hosting

Have you ever tried to do a recursive linux search for a text string inside a particular file? For example
grep -r "mail" *.php
and then it fails because the current folder doesn’t have any php files in it?

Here is how you can achieve a search inside all .htaccess files for the text php_flag

find -iname .htaccess | while read line; do grep --with-filename "php_flag.*" $line; done

This below line will search all .PHP files for a common hack script

find -iname *.php | while read line; do grep --with-filename "eval (base64_decode('aWYoIWlzc2V0KCR" $line; done

If that gives you too much output, here is a search that will only display the filenames

find . -name "*.php" | while read line; do grep --files-with-matches --with-filename "base64_decode('aWYoIWlzc2V0KCR" $line; done

Tags: ,

Advanced File Deletion in Linux

June 13th, 2009 by Sameer | No Comments | Filed in Hosting

Here is a cool way to delete files according to some complex rules without knowing complicated bash commands.

First, create a file as follows that contains your deletion rules.

+ public_html/
+ public_html/*
- access-logs
- etc/
- logs/
- mail/
- .cpanel/
- .cpaddons/
- .spamassassin/
- .ssh/
- public_ftp/
- cpmove.psql/
- tmp/
- cpeasyapache/
- MySQL-install/

Then, run rsync with the source and destination folder being the same
rsync -avz --include-from:rulesFile.txt . . --delete-excluded

You can add –dry-run if you want to see what will be deleted:

rsync -avz --include-from:rulesFile.txt . . --delete-excluded --dry-run

Tags: