Using find on Linux
find /directory -name 'search term'
Search files in subdirectories of current directory:
find . -name 'search term'
Find large files:
find / -type f -size +100000 -exec ls -lh {} \;Search inside file contents:
find . | xargs grep --color=auto -iR 'search term' *or
find . -type f -exec grep -lR 'search term' {} /dev/null \;Find files modified in certain time period:
find . -name 'search term' -mtime -1 -print
Exclude certain directories in search:
find . -name 'search term' -prune -o -name 'excluded directory1' -prune -o -name 'excluded directory2' -prune -o -type f -print
Find files older than a certain date (2 days in example) & delete:
find . -mtime +2 -exec rm {} \;Find and replace in files:
find ./* -type f -exec sed -i 's/search term/replacement/g' {} \;Script to sort & show directory sizes in Linux
Just change /www/htdocs/ to the desired directory that you want to see the subdirectory sizes for, sorted by size descending.
#!/bin/bash
du -k /www/htdocs/* | sort -nr | awk '
BEGIN {
split("KB,MB,GB,TB", Units, ",");
}
{
u = 1;
while ($1 >= 1024) {
$1 = $1 / 1024;
u += 1
}
$1 = sprintf("%.1f %s", $1, Units[u]);
print $0;
}
' > filesize.txt
Rotate Apache (or any) logs on linux
Logs can quickly grow to take up disk space. To alleviate this problem, install logrotate if your distribution does not come with it already. Edit /etc/logrotate.conf changing the first line to the period when you want to rotate the the logs (daily, weekly, monthly, yearly). Change the rotate command under that to how long you want to keep old logs for, e.g. if rotating logs every month and to keep the logs for a year use rotate 12.
Edit (or create if necessary) /etc/logrotate.d/httpd to contain the following:
/usr/local/apache/logs/*_log {
monthly
rotate 12
compress
missingok
notifempty
sharedscripts
postrotate
/usr/local/apache/bin/apachectl graceful
endscript
}
Where:
- monthly: time period elapsed before the logs are rotated
- rotate 12: logs are rotated 12 times before being removed (i.e. 1 year), if set to 0 old logs are removed rather then rotated
- compress: old logs are compressed with gzip to save disk space
- missingok: if logs are missing skip and do not issue an error
- notifempty: do not rotate empty logs
- sharedscripts: only run postrotate command once for all the logs in the specified directory, rather for each log
- postrotate: command to run after logs are rotated, necessary for apache to start logging again
Be sure the paths /usr/local/apache/logs/*_log and /usr/local/apache/bin/apachectl graceful are correct for your configuration. Graceful will restart apache without ending any current requests being served.
Thanks to nixCraft for the hints.
Disable all catchalls on entire cPanel server to prevent spam
By default cPanel is set to accept catchalls, that is mail to non-existent users, and bounces them. This can result in much spam being accepted by a cPanel server as spammers often brute force or randomly address their spam. Further, the bounce is usually set to an innocent address that was spoofed, creating what is an increasing problem known as backscatter spam.
A few steps are required to completely fix this. First disable this default setting in cPanel WHM by going to Server Configuration > Tweak Settings > Mail > and set Default catch-all/default address to :blackhole:. This will silently drop spam rather than bounce it, preventing more backscatter spam.
Next, disable all catchalls on the server:
mkdir -p /etc/valiasesbak cp -R /etc/valiases /etc/valiasesbak sed -i 's/^\*: [^ ]*$/*: :blackhole:/g' /etc/valiases/* replace ':fail: No Such User Here' ':blackhole:' -- /etc/valiases/*
Check if there are any lingering aliases set to bounce with:
grep '*:' /etc/valiases/* | egrep -v ':blackhole:'
There maybe a few other bounce fail phrases like “Invalid e-mail address. Check and re-send.” Simply substitute these phrases in the replace command above, so:
replace ':fail: Invalid e-mail address. Check and re-send.' ':blackhole:' -- /etc/valiases/*
Ensure users can write with:
chmod 777 /etc/valiases/* chown nobody:nobody /etc/valiases/*
Lastly, prevent users from re-enabling the catchall. In WHM > Packages > Feature Manager, select Default under Edit a Feature List and then edit. Uncheck Default Address Manager and then save.
Thanks to Fidget for some help.
Get Redhat updates without subscription, fix cPanel “No method to auto repair package system” EasyApache error
A Red Hat 4 server could not rebuild Apache or PHP with cPanel’s EasyApache. It kept getting a no method to auto repair package system error. cPanel support said this was due to the Red Hat subscription expiring.
Instead of paying for another $375 subscription just to get some updates, I migrated the server to the corresponding Centos 4.x release. I then made the proper packages were excluded in the first yum [main] block:
exclude=apache* bind-chroot courier* dovecot* exim* httpd* mod_ssl* mysql* nsd* perl* php* proftpd* pure-ftpd* ruby* spamassassin* squirrelmail*
and then yum list and yum update worked.
Install Ubuntu without CD over network with ISO
There are a few ways to install Ubuntu without a CD. The following worked for me using an ISO: