One of the nice things about Linux is that most of the freely available software also makes available its source code. So all you have to do is find an application that already does what you want to know how to do and look at its source code.

gg