Change Permissions For Directories Only
by Kyle on
find . -type d -exec chmod 755 {} \;
Change Permissions For Files Only
by Kyle on
find . -type f -exec chmod 644 {} \;
Delete Files Except Ones With Certain Extension
by Kyle on
find . ! -name "*.php" -exec rm -f {} \;
Delete Zero Size Files
by Kyle on
This will delete all files in the current directory that have a size of zero.
find . -type f -size 0k -exec rm {} \; | awk '{ print $8 }'
Find And Delete Files Older Than X Days
by Kyle on
Delete files older than X days:
find . -type f -mtime +X -exec rm {} \;
If you want to search a specific directory:
find /path/to/files -type f -mtime +X -exec rm {} \;
You can also delete directories by switching the flag type:
find . -type d -mtime +X -exec rm {} \;
Find Duplicate MySQL Records
by Kyle on
SELECT email, count(email) AS total FROM `tbl_mailing_list` GROUP BY email HAVING total > 1 ORDER BY total;
Get Total Inode Usage
by Kyle on
find . -printf '%i\n' | sort -u | wc -l
List Inode Count For All Directories
by Kyle on
for i in `find -type d -maxdepth 1`; do echo -n $i; echo -n " "; find $i | wc -l ; done
MySQL Find And Replace
by Kyle on
UPDATE `tbl_name` SET tbl_field = replace(tbl_field, 'FIND', 'REPLACE');
Recursively Delete .DS_Store Files
by Kyle on
find . -name *.DS_Store -type f -exec rm {} \;
Recursively Delete All .svn Directories
by Kyle on
find . -type d -name .svn -print0 | xargs -0 rm -rf
You can also run the following command:
find . -type d -name .svn -exec 'rm -rf {}\;'
Recursively Find And Delete Files
by Kyle on
This command will recursively search for a file and remove it.
For example, if you wanted to delete all index.html files, you would do this:
find ./ -name 'index.html' -exec rm '{}' ';' -print
If you wanted to remove all files ending in .html, you would do this:
find ./ -name '*.html' -exec rm '{}' ';' -print
Recursively Find And Replace Text Inside Files
by Kyle on
find . -type f -print | xargs sed -i -e 's/FIND/REPLACE/g'
Remove Iframe Injected Code
by Kyle on
If your index.html and index.php files have suffered from an iframe injection, you can use the following grep/sed command for clearing it out.
Please be careful and test first with just the grep command to ensure you don't clear out anything you don't need.
This command does not backup files!
grep -lr -e '<iframe src="http://.*</iframe>' * | xargs sed -i 's/<iframe src="http:\/\/.*<\/iframe>//g'
Search Inside Files And List Matches
by Kyle on
find . -type f -exec grep -l 'KEYWORDS' {} /dev/null \;
Search Strings In PHP Code
by Kyle on
find . -name "*.php" -exec grep string {} \; -exec echo -e {} \;