Linux User’s Guide to Mac: Terminal

Few things in Unix match the importance of the terminal emulator.  Having a nice GUI is fine, but nothing beats the command line, which some have said is the «front line» of computing. As an official member of the Brotherhood of the Commandline, I have always kept at least one terminal window open at all times, and often three or more.

In Mac Land, that’s Terminal. Yes, I could run the X server and use Xterm, but that would be a step backward from the one thing which drove me away from Unix in the first place. I came to Mac because I didn’t have to use the X server to get a GUI, since Mac has the best one out there. Whatever I needed to do on the command line requires making Terminal do it right. By default, Terminal has some rather odd behavior for someone coming from Unix, and more if your Unix is Linux. Most of it can be changed. One thing you will not get is the mouse-paste. That’s unique to the X server. Sure, you can get a mouse driver for Logitech or Intellimouse which will let you alter the wheel button behavior, but it breaks other, more versatile and useful behavior, so you might as well get used to Cmd+C and Cmd+V. But most other things can be adjusted to behave as we Unix people have come to expect.

For this demonstration, I’m using Joe as the application which will most readily lend itself to explaining what we need to do. Joe’s Own Editor offers a quick and easy method to editing the configuration file to add non-default keystrokes. A couple of years ago I wrote a HOWTO on customizing Joe’s keystrokes based on work by Anne Baretta and a few tips garnered here and there. In our last installment, we covered installing Joe and Aspell, so I’m assuming you either have them already, or can grasp what follows without them.

First, grab a copy of your system joerc for your $HOME folder (using the command line, of course):

cp /usr/local/etc/joe/joerc ~/

cp /usr/local/etc/joe/ftyperc ~/

If you have the latest version of Joe, you’ll probably want to modify the ftyperc for your own use, as I do. But first, we have to understand the fundamental difference between Mac’s Terminal and your generic Xterm. Terminal has some different default actions assigned to some of the keystrokes. More, as my HOWTO encourages assigning F-keys to Joe actions, you’ll need to consider doing something I did: turn them off in the Mac GUI.

For serious Mac users, this is probably anathema. For Unix users, having all or most of the F-keys available for the applications is pretty important. In Mac’s System Preferences, go to Keyboard & Mouse, and open Keyboard Shortcuts. For me, the simplest answer was to en masse turn off «Keyboard Navigation» shortcuts because I use the mouse for those things, if at all. Then I added «Dock, Expose and Dashboard» because I can’t imagine why I would want them. Your mileage may vary, but if you want the F-keys for Terminal, consider it.

In my HOWTO on Joe’s keystrokes, I point out the method of determining what keycodes are output by your terminal emulator of choice, by hitting CTRL+V, followed by any other key or combination with modifiers. This works in Terminal. However, you’ll notice they all include the «escape sequence» of ^[ which represents hitting the ESC, but forms a part of what Joe needs to interpret custom keystrokes. However, when you open the Preferences dialog in Terminal, choose a profile (I set Pro as my default), and click on the «Keyboard» setting page, you’ll see most of them are in the pattern of 33xxxx. If you understand that 33 is equivalent to ^[, you can do this.

Now, scanning down through the list of default keystrokes in this dialog, we see why the «gray keys» won’t work without holding down the SHIFT key. Change those assignments. You’ll need to assign them to a «string» instead of any of the optional actions. Just select any of the gray key names and then click «Edit» and select the option to send a string. Below are various strings as they are output in most Xterms, which is what most command line applications are expecting, even when compiled on Mac. I have broken down the spacing as Joe uses the Xterm output, according to the instructions in my HOWTO.


Joe format

Mac label

Terminal format


^[ [ C

cursor right




^[ [ 1 ; 5 C

control cursor right



^[ [ 1 ; 3 C

option cursor right


In order to tell Terminal to output that second command as I wished, I had to remove the default and tell it to send the string in the last column of the second row above. Furthermore, I have to warn you the dialog will attempt to interpret any deleting keystrokes, so neither DEL nor BKSP can be used to clear a string in that dialog. You’ll need to highlight with the mouse, then either overtype or paste what you want there.

Below are all the arrow keys and gray keys except the HELP and DEL keys on Mac keyboards. Use those you need. In some cases, you’ll have to use the + button the dialog interface to add the keystrokes not included by default, along with any modifiers.


Joe format

Mac label

Terminal format


^[ [ D

cursor left



^[ [ 1 ; 5 D

control cursor left



^[ [ 1 ; 3 D

option cursor left



^[ [ A

cursor up



^[ [ 1 ; 5 A

control cursor up



^[ [ 1 ; 3 A

option cursor up



^[ [ B

cursor down



^[ [ 1 ; 5 B

control cursor down



^[ [ 1 ; 3 B

option cursor down



^[ [ H




^[ [ 1 ; 5 H

control home



^[ [ 1 ; 3 H

option home



^[ [ F




^[ [ 1 ; 5 F

control end



^[ [ 1 ; 3 F

option end



^[ [ 5 ~

page up



^[ [ 5 ; 5 ~

control page up



^[ [ 5 ; 3 ~

option page up



^[ [ 6 ~

page down



^[ [ 6 ; 5 ~

control page down



^[ [ 6 ; 3 ~

option page down


Once you have told Terminal what keystrokes you want added and the strings to send, you are ready to edit your joerc according to the HOWTO linked above. Note that the ftyperc is where you put your specific options regarding various filetypes. For plain text (.txt), I use the following format options:

Text file. *.txt


-tab 3

-indentc 32

-istep 1



-rmargin 72


I use the same for HTML files. The explantion for each one can be found in the joerc file.

There is one more peculiarity I’ve found in Terminal. For some strange reason, F1-F3 tend to output something different than what Joe expects, and probably most other command line programs from Unix. In my joerc, instead of using the standard .k1, I had to pickup the code output from Terminal as revealed by the command CTRL+V: ^[OP. Then, I placed this in my joerc where I wanted to use F1, after spacing it out properly. I did the same for F2 and F3.

After you’ve added your custom keystrokes and commands to joerc, make sure to change the «include» statement for your ftyperc (approximately line 360). It must be the full path. Mine says this:

:include /Users/edhurst/.ftyperc

Which brings up the last point of renaming them both by adding a period to the front of the file so they are read as configuration files:

mv joerc .joerc

mv ftyperc .ftyperc

After modifying the Terminal profile keystrokes, I tested a few other applications and they seemed to work okay. Enjoy.


Taken from: Open For Business

HowTo reinstall – restore GRUB in UBUNTU

After a windows fresh install, the windows setup decided to drop MBR to put its stuff in. 
This is an old trick, but udev added a little complexity, so let’s give it a try. First boot on a Ubuntu CD, open a console and run:
(here linux partition is sda2, second partition on a sata disk)
mkdir /media/mnt mount /dev/sda2 /media/mnt/ mount -o bind /dev/ /media/mnt/dev chroot /media/mnt => now you are on the destination disk, so you can install grub. grub-install /dev/sda
Of course you can do a lot more stuff, like changing fstab etc etc .. but the trick is to mount + mount bind + chroot

Ignore duplicate entries in MySQL select using DISTINCT keyword

Sometimes every occurance of a value which may be duplicated multiple times in a result set is not needed. For example, if making a pulldown menu list of options, each option should be seen only once. The DISTINCT keyword in a select statement eliminates duplication in the result set.

The column party from the presidents sample table has many repeats in it. To select a list of the parties from the table, use:

SELECT DISTINCT party FROM presidents;

This returns a result set that looks like:

| party |
| no party |
| Federalist |
| Democratic-Republican |
| Democratic |
| Whig |
| Republican |

Using the DISTINCT keyword on queries with multiple columns will return unique combinations of values on all of the columns. For example, the query

SELECT DISTINCT givenname, party FROM presidents;

returns 36 out of a possible 43 rows. Each row is a unique combination of first name and political party.

Rename or change name of MySQL table

If you change your mind and want to rename an existing MySQL table, with or without data in it, it is no problem. One simple command will change the table’s name.

To change the name of an existing table old to new, use this command as a user with adequate privileges:


It is good DBA manners to make sure that no one and no program are using this table before making the name change.