Top

Archive of articles classified as "Programming"

Back home

When programming, it is common to spend a lot of time using a command-line shell. On the Mac, the program used is Terminal.

Recently I discovered that it is possible to spruce up the mundane appearance of Terminal by adding color. There are two techniques that I will show to add color, one to colorize the output from the 'ls' command, and another that colorizes the two simple text editors, nano and pico.

First, let us begin with colorizing the 'ls' command, which is helpful for file system navigation. With this setting, directories are displayed as one color, regular files another, executables yet another, and so on. To make this happen, add the following two lines to either ~/.bash_profile to apply for just the single user, or to /etc/bashrc for all users.


Read full article »

hit “Tab” twice to list all available commands (there’s a lot!)
help also lists some commands and their options
man command to get the full list of options available for that command
q to exit man pages

Navigation

cd to change directory
When you open the terminal it should default to your user area, so just typing cd desktop should be all you need to get to the desktop.
.. represents parent directory
cd .. to move to parent directory


Read full article »

Regular Expressions

if ($line =~ /http:/) { ..do something.. }
checks $line for the substring “http:”, and returns true if it exists
/[^:]+:/ makes a match to any string that has a ‘:’ and does not have a ‘:’ preceding it
/\d{5,7}/ makes a match if the string is 5 to 7 digits
\b matches a word boundary
/i in match means case insensitive
next LINE if $line =~ /^#/ skips line if the line starts with the comment sign


Read full article »