Note: These are not all for the command line. There are so many other tricks we learn along the way and they are seldom documented. If you know others please throw them in the comments.

MySQL Tip:
When you run a normal query in MySQL prompt, if your table is larger than your monitor, you get a jumbled mess of data. It is incredibly hard to read and makes for slow going. The following command replaces the common “;” with a “\G” to complete your command and displays the data in a clean vertical fashion.

mysql> select * from stores where id = 1\G

*************************** 1. row ***************************
                            id: 1
                    company_id: 3
                          name: Cool Hunting
                      verified: 0
       customer_service_number: (310) 698-3333
                    dispatched: 335863038
         service_type_bit_mask: 1
              test_location_id: NULL
         reference_location_id: NULL
              gps_refresh_rate: NULL
1 row in set (0.00 sec)

VIM Tip:
(Shift-j) Dealing a lot with small polygone data points, I require sets from legacy applications and product people – often mistreated and malformed or in old formats.

For example, consider this dataset.

"-117.317 33.084", 
"-117.31 33.084", 
"-117.31 33.092", 
"-117.301 33.091", 
"-117.293 33.091", 
"-117.284 33.091"

This isn’t bad, but there might a thousand reasons why you need the white space reduced or the data on one line, so in command mode in Vim type:

8 shift-j or shift-j 8 times. I prefer the former.

This will result in all the data points to move up to one line.

"-117.317 33.084", "-117.31 33.084", "-117.31 33.092", "-117.301 33.091", "-117.293 33.091", "-117.284 33.091"

Command Line Tips:
SSHing to servers or remote DBs is a common action for most development but copying and pasting or trying to remember a freeway of flags is cumbersome.This next command has become the norm of my daily development.

Try the following on the prompt:
Type cntl-r. A prompt will appear below your line. If you type a the first characters of where/what you want to do bck-i-search will autocomplete for you. Pretty sweet!

➜ cntl-r

bck-i-search: _

➜   ssh                                        
bck-i-search: ssh_

cntl-s brings up a forward search, but I have no idea on the use case for this. Can the command line tell your future?

➜ cntl-s

fwd-i-search: _ 

Also, a few more handy things

➜ cntl-a => beginning of a line
➜ cntl-k => delete everything forward
➜ cntl-e => end of a line


Leave a Reply

Your email address will not be published. Required fields are marked *