Tag Archives: linux tips

Bash Script to scan folders and PHP files for bad permissions

This script will run through all Cpanel user account home directories and recursively do the following:

  • check for directories that have the write bit set for group(g) or other(o) – and reset any found to 755 permissions.
  • check for any files with the .php extension and that have any access bits at all allowed for other (o), write/execute bits set for group(g), or execute bit set for user(u) – and reset any found to 640 permissions.

It is quite easy to modify for your own purposes, but these permissions are generally a good starting point when on a server running PHP with the suPHP module (THIS WILL BREAK EVERYTHING IF YOU ARE RUNNING PHP AS DSO). Read More…

Applying RewriteCond to Multiple RewriteRule in .htaccess

Just a quick hints and tips update for today. On a number of my sites I have been using mod_rewrite to produce SEO friendly URLs. e.g. :


instead of something like:


This is done using RewriteCond and RewriteRule statements in .htaccess. However, normally RewriteCond only applies to the RewriteRule immediately following it. This means we end up with horrible repetitive blocks of code in our .htaccess files. In this article I’ll show you how to rationalise this problem and shorten your code! Read More…

How to determine Linux Memory Usage?

Free memory on Linux is a very different world to the one that most people would be used to. For years windows users have installed odd bits of memory management software in a desperate bid to see the biggest green segment of the memory pie chart. Well, it can be argued that any good operating system SHOULD make full use of the installed memory. Why continually unload and de-allocate memory when you are probably just going to have to load it up again shortly after?

The Linux kernel uses something known as lazy de-allocation – which means that although the memory pages may not be used, they are left un-wiped from memory in case they are needed again. Think about common linked libraries and such. Linux only keeps a few pages of memory actually free, so that it has the ability to load stuff quickly, and THEN think about de-allocating memory to make more space if it has to. Read More…