Get Source Code for any Linux Command

by Ramesh Natarajan on February 19, 2010

Question: How do I get source code of any Linux command?

Answer: For Debian family Linux distributions, you can get source code for any Linux commands using one of the two methods mentioned below.

Method 1: Get Source Code Using apt-get

Step 1: Add a Source URI to sources.lst

$ cat /etc/apt/sources.list
deb-src lenny main
$ apt-get update

Step 2: Execute apt-get source to get the source

For example, to get source code for netstat command, do the following:

Syntax: apt-get source command-name

Example: apt-get source netstat

Method 2: Get Source Code from

If you are not pretty sure about the package name, you can navigate through the ‘Sections’
page here:

  • Click on the topic of the command you wanted to get the source.
  • Search for the command you are looking for, and click on it.
  • In the right side bar, you will have a link to download source package.

Example: Download the source code of the vim editor

  • Step 1: Go to the listing page of Lenny in
  • Step 2: Click on the link that says ‘editors’
  • Step 3: Search and go to the vim editor page
  • Step 4: In the right side bar, select and download: vim_7.1.314.orig.tar.gz

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 9 comments… read them below or add one }

1 Grim February 19, 2010 at 2:32 am

I’d like to see info how to get sources in CentOS and Fedora

2 Athul February 19, 2010 at 3:37 am

I basically use google code search for searching through and finding particular snippets of open source codes. Think that is also good option in addition
to the above if we just want to analyse some part and dont want to do build it.

3 g-ss February 19, 2010 at 6:00 am

you can always install debian in a virtualbox to get that working

4 Milan Cvejic February 19, 2010 at 10:07 am

You can find package sources for centOS here:
Then you need just to install rpms for sources that you want.


Milan Cvejic

5 jameslee February 20, 2010 at 9:06 pm

please provide for rpm packages also

6 Ramesh Natarajan February 26, 2010 at 5:09 pm


Google code search looks great. Thanks for sharing it.


Use the method suggested above by Milan to get source code of the rpm packages (which is RedHat based). CentOS is based on RedHat code base.

7 Abhijeet April 10, 2012 at 11:03 am

Worked for thankz maan!!!!!

8 KDG June 30, 2013 at 5:55 am

How can I obtain source codes for ubuntu family apart from code search?

9 leonardo gama February 8, 2014 at 9:24 pm

Thank you!!! You helped me so much!!

Leave a Comment

Previous post:

Next post: