Archive for October, 2009

Renaming files – Adding a suffix to the file name

Posted on October 23rd, 2009 in Web Development | 1 Comment »

The solution provided in Easily Renaming Multiple Files works perfectly well if we want to add a prefix to a file. This solution does not work too well if you want to add a suffix.

Objective: For all jpegs in a folder add the suffix _tn after the file name and before the extension.
Example: file1.jpg = file1_tn.jpg

In the console type the following:

for i in *.jpg ; do mv $i `echo $i | sed 's/\.jpg/\_tn.jpg/'` ; done

If the file name was in CAPS and and you’d rather have your file name in lowercase pipe the following on:

for i in *.jpg ; do mv $i `echo $i | sed 's/\.jpg/\_tn.jpg/' | tr [:upper:] [:lower:]` ; done

Setting up SSH public/private keys on OS X

Posted on October 13th, 2009 in Web Development | No Comments »

Sometimes it’s a little bit of a pain to constantly type your password every time you log in to a server. If you are pushing code, moving files, backing up data, typing your password at each step of the way can be annoying. By setting up public/private keys between your local machine and the remote server you can eliminate that step.

Type the following on the local machine:

ssh-keygen -t dsa

You will see the following after typing the command above. You can press enter and skip the question when you’re asked for a file name, but for the passphrase try not to leave it blank:

Generating public/private dsa key pair.
Enter file in which to save the key (/Users/amitsamtani/.ssh/id_dsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/amitsamtani/.ssh/id_dsa.
Your public key has been saved in /Users/amitsamtani/.ssh/id_dsa.pub.

If you did not change the file name copy the contents of ~/.ssh/id_dsa.pub to the remote servers ~/.ssh/authorized_keys file. Append the contents to the end of the file.

After this is complete, on your first attempt to ssh into the remote server you will be presented with a prompt by OS X to type the id_dsa.pub passphrase. Type the passphrase into the prompt and save it in your keychain.

Now you can log in to the server without the need of the password.

WordPress – Move existing blog to a development server

Posted on October 5th, 2009 in Web Development | 1 Comment »

First tar/gzip the blog and the database:

tar -cf old_blog.tar blog/
gzip old_blog.tar
mysqldump -h hostname.com -u username -p database_name > dump.sql
gzip dump.sql

Bring the blog and database to your local machine and set it up. For simplicity sake we will assume that the database name, username and password is the same as your live server.

scp user@hostname.com:/path/to/files/old_blog.tar.gz .
scp user@hostname.com:/path/to/files/dump.sql.gz .
tar -xzvf old_blogtar.gz
tar -xzvf dump.sql.gz
mysql -h localhost -u user -p database_name < dump.sql

Log in to your database and change the values of siteurl and home in the wp_options table to point to your local machine’s domain:

update wp_options set option_value = 'http://localhost:8888/domain.com' where option_name in ('siteurl','home);

wget

Posted on October 5th, 2009 in Web Development | No Comments »

I just realized I do not have a copy of wget on my installation of Snow Leopard. If you need it, its just a matter of getting the latest code via curl and installing.

curl -O http://ftp.gnu.org/gnu/wget/wget-latest.tar.gz
tar -xzvf wget-latest.tar.gz
cd wget-1.12
./configure --prefix=/usr/local
make
sudo make install

Now lets use wget in an example:

wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
mv wordpress new_blog

Very nice!