search
top

How to search for a string within files (recursively)

#!/bin/sh
#
# Script to search recursively for a string in the current directory
#
 
if [ "" == $1 ]
        then
        echo "Please specify a string to search for."
 
else
        grep -ril $1 .
 
fi

If you want to look for a string in specific files, you can do the following:

#!/bin/sh
#
# Script to search recursively for a string in the current directory
#
find . -type f -name $1 -exec grep -rilo $2 {} \;

grep:
-r = recursive
-i = ignore case distinctions
-l = only print FILE names containing matches
-o = show only the part of a line matching PATTERN

VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)

How to display the filesize of directories

du -ch | grep total
VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)

How to find and replace a string in MySQL

UPDATE `table_name` SET `column_name` = REPLACE(`column_name`, 'original_string', 'replace_string')
VN:F [1.9.14_1148]
Rating: +1 (from 1 vote)

How to create and extract a tar-file (.tgz) of a directory

Create:

tar -cf your-tarfile.tgz your-directory/

Extract:

tar -xf your-tarfile.tgz your-directory/
VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)

How to use a different (second) database in CakePHP

/app/config/database.php code:

var $connectionName = array(
           'driver' => 'mysql'
     ,     'persistent' => false
     ,     'host' => 'localhost'
     ,     'login' => 'your-username'
     ,     'password' => 'your-password'
     ,     'database' => 'your-database'
     ,     'prefix' => ''
);

In a random model:

$this->useDbConfig = 'connectionName';
VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)

How to add files to your SVN repository recursively

svn status | sed -n '/^\?/ s/\? //; s/ /\ /p' | xargs svn add
VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)

CakePHP e-mail displays weird characters (=0D=0A=0D=0A)

Cause: you’re sending your e-mail as HTML only.
Solution: send the e-mail as “both”, like this:

$this->Email->sendAs = 'both';
VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)

Remove files that are older than x days

First you want to see which files will be deleted. This examples looks for files older than 7 days.

find /directory/to/search/through/ -type f -mtime +7 -print | xargs echo

If you’re satisfied with the list, you can actually delete them:

find /directory/to/search/through/ -type f -mtime +7 -print |  xargs rm -f
VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)

Prevent data from being overwritten in your controller save action

Before you perform your save, execute a create first. This prevents data from being overwritten due to an ID being set that you didn’t know about.

$this->Model->create();
$this->Model->save($aYourData);
VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)

Set rewrite rules so your domain always includes www

Add the following to your .htaccess file:

<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteCond %{http_host} ^yourdomain.com [NC]
	RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
</IfModule>
VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)

« Previous Entries

top