Bash

Categories:

Search and replace within files with bash

find ~/httpdocs -maxdepth 1 -name \*.php -exec perl -pi -w -e "s/\<\/body\>/\<\?php\ include_once\('includes\/footer_inc\.php'\);\ \?\>\<\/body\>/g" {} \;

THANK YOU KYRA!!!

Standard cron job for Drupal

Hourly cron job:

crontab -e
* 1 * * * /usr/bin/wget -O - -q -t 1 http://www.domain.com/cron.php

Rsync mirror files excluding svn files

This rsyncs from a ssh server to your local machine, excluding svn files, and it has delete flag so its a mirror copy.

rsync -av --delete --progress --exclude '.svn/' username@domain.com:/some/directory ~/Desktop/backup/

Extract tar.gz files in a folder then delete them

find . -name '*.tar.gz' -exec tar -zxf {} \;
rm *.tar.gz;

Reset all your files and directories back to the server defaults of 755 and 644

The following commands reset all your files and directories back to the server defaults of 755 and 644.

    find . -type f -exec chmod 644 {} \;
    find . -type d -exec chmod 755 {} \;

Create symbolic link

ln -s {target-filename} {symbolic-filename}

Recursively Delete all DS_Store Files

find . -name *.DS_Store -type f -exec rm {} \;

Send standard output to a file

echo hi > file.txt

single ‘>’ replaces file

echo hi >> file.txt

double ‘>>’ appends to file

Send error output to text file

somecommandthatmakeserrors 2> error_log.txt