Monday, January 11, 2010

Python Path

When you install a new package in python, it is very likely the path of the installation is not set. Set PYTHONPATH variable to handle that.

Example in bash:
export PYTHONPATH=$PYTHONPATH:/opt/local/lib/python2.5/site-packages/

Example in csh:
setenv PYTHONPATH "${PYTHONPATH}:/projects/Common/PYTHON/Python-2.5.1-all/numpy1
11/lib/python2.5/site-packages"

This should take care.

Sunday, August 16, 2009

Renaming a bunch of files in one line

I recently wanted to rename a bunch of files. There is a one line command to do it. Lets say you have a bunch of files named old1.jpg ... old100.jpg. And you want to rename them as los-angeles-1.jpg .. los-angeles-100.jpg. This is how you do it on a mac shell:

ls old*.jpg | awk '{print $1 ," los-angeles-"substr($1,4)}'| xargs -n2 mv

This should do the trick. Here is an explanation:
The first part ls old*.jpg lists all the files.
The above is piped to awk, and we ask by awk '{print $1 ," los-angeles-"substr($1,4)}' to print the file name itself ($1 part) and " los-angeles-"substr($1,4) prints them as los-angeles-1.jpg and so on.
Finally, we pipe this output to xargs, with a -n2 flag which tells xargs that there are two inputs to mv.

Happy mv-ing.

Tuesday, May 19, 2009

Understanding make

If you are compiling code in unix based operating system, then you cannot escape the omnipresent Makefile. Well, writing a Makefile requires some knowledge of the basics. Here are some tips to get by.

> make -p
Displays all the macros available in make.

One particular macro that floats around a lot is the @ macro. This is a macro that make defines for each dependency line. In a code such as:

prog : file1.o
${CXX} -o $@ file1.o

"$@" interprets as "prog"

Sunday, May 17, 2009

Showing hidden files on Finder

How do you view hidden files on a finder? Try the following on a command terminal.

To show all hidden files:
> defaults write com.apple.finder AppleShowAllFiles YES
> killall Finder


To undo and hide hidden files on finder:
> defaults write com.apple.finder AppleShowAllFiles NO
> killall Finder

Saturday, May 16, 2009

Configuring X11 and Terminal

Here is a blog to note down some of my discoveries on how to work with UNIX/Mac OS X. Some tid bits for survival.

In Mac OS X 10.5, if you want to set alias and stuff, then you can do the following:

Edit .profile file in the home directory to configure the Terminal
Edit .bashrc if you want to configure X11

Some nice options to set as aliases:
alias ls='ls -G' : Color option for listing