Change a Raspberry Pi's Hostname without Rebooting

To change a Raspberry Pi's hostname without rebooting, follow these steps. In this example, I will be changing the hostname from "alpha" to "beta".
1. Edit /etc/hostname
The hostname file is just a single line with your current hostname on it. Edit the hostname file with this command
sudo nano /etc/hostname
and change the line in the file from the current name to the one you want. I would change it from alpha to beta in this instance.
2. Edit /etc/hosts
The hosts file tells your Pi how to resolve any addresses that you place there. Mine looks like this:
127.0.0.1       localhost
::1             localhost [...]
fe00::0         ip6-localnet
ff00::0         ip6-mcastprefix
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

127.0.1.1       alpha
and I would change it to look like this:
127.0.0.1       localhost
::1             localhost [...]
fe00::0         ip6-localnet
ff00::0         ip6-mcastprefix
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

127.0.1.1       beta
3. Update hostname with hostname.sh scriptNext, execute this command:
sudo /etc/init.d/hostname.sh start
This will refresh the hostname for the Raspberry Pi without rebooting it. Now, if you open a new terminal, the prompt will say username@newhostname:~$ and your hostname is changed.