Open Command Prompt Here Feature in Vista

There is a very handy PowerToy for Windows which allows you to right-click any directory in the File Explorer and an option to “Open Command Window Here” would show up in the contextual menu. This option would allow you to open up a command prompt window with the directory already set to the directory you right-clicked on.

This feature is built into Windows Vista and can be activated by right-clicking on a directory name while holding down the shift key. When you do this, the contextual menu option “Open Command Window Here” will appear.

How to Recursively chmod Directories or Files

Command to recursively chmod only directories:

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

How to recursively set the execute bit on every directory:

chmod -R a+X *

The +X flag sets the execute bit on directories only

How to recursively chmod only files:

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

How to recursively chmod only PHP files (only for PHP files with the extension .php):

find . -type f -name '*.php' -exec chmod 644 {} \;

You can change the “.php” in the line above to whatever file extension that you want.

How to Change the Port on NX Server

NX Server is a commercial application released by the company NoMachine. It allows you to connect to your Linux server similar to how you would connect to a Windows computer using remote desktop. NoMachine offers a free version of the product which has a restriction of only allowing 2 simultaneous connections to the server. NX Server runs over SSH so you don’t need to open any other ports on your firewall other than the port for the SSH service.

It is considered a good security practice to change the default port the SSH service listens on. When you change this port it breaks the NX Server service since it expects the SSH service to be running on the default port of 22. You can fix NX Server by modyfing the following file:

/usr/NX/etc/server.cfg

Set the following settings in the file:

SSHDPort = "22"
SSHDAuthPort = "22"

Change “22” to whatever port your SSH service is now listening on. You’ll then need to restart the NX Server service to put the changes into effect:

/etc/init.d/nxserver restart

NOTE: The instructions above were tested on a Linux Red Hat 5 server.

How to Query Multiple Databases in PHP

You can perform a SQL query against more than one database with PHP. Here is a sample generic SQL query against two databases:

SELECT image.image_title, greetings.date
FROM db1.image, db2.greetings
WHERE greetings.image_id=image.imageid

And here is some PHP sample code on how you would query two databases in a single SQL statement:

$query="INSERT INTO db1.table1 SELECT * FROM db2.table2 WHERE a=1";
mysql_query($query,$connection);