In this post, I will be explaining you to how to get the source code of any package in Ubuntu.
Let us take one example and pull the source code. If you want to get the source code of 'ls' command in Ubuntu, First you need to know which package has bundled this command.
1. First find the absolute path of the command wither by 'which' command. If it didn't get the command name, then your PATH variable is not set properly. No worries, search for the binary in your machine with find command.
%which ls
OR
% find / ls 2>/dev/null
Let us say we got '/bin/ls' as output.
2. Now get the package name which bundled this command.
%dpkg -S /bin/ls
coreutils: /bin/ls
3. Coreutils is the package which bundled /bin/ls command.
Before going to pull the source of this package, configure the apt by uncomment all the lines starts with 'deb-src' in /etc/apt/sources.list file as a root user. After doing this run apt-get update.
%apt-get update
4. Create a directory where root has write permission. and go to that directory. run below command to get the source code of the package.
%apt-get source coreutils
5. You will get the below files as part of this download. here we will be having 3 files and 1 directory.
coreutils-8.20 ---> Directory which is extracted code of coreutils_8.20.orig.tar.gz.
coreutils_8.20-3ubuntu5.dsc ---> Description of the package, dependency list and signature.
coreutils_8.20-3ubuntu5.diff.gz ---> Patch, which enables the source code build on ubuntu.
coreutils_8.20.orig.tar.gz ---> Original GPL code
**** you can find the source code for ls command in 'coreutils-8.20/src/ls.c' file. ****
6. Applying patch to the source code.
First extract the gzipped diff file and then apply patch to source code.
%gunzip coreutils_8.20-3ubuntu5.diff.gz
% cd coreutils-8.20
%patch -p1 < ../coreutils_8.20-3ubuntu5.diff
Now you can build the source code and install your own binaries in your Ubuntu machine.
Thanks
Shivu










