2

I often come across interesting Linux commands that make me wonder; what are these commands actually doing?

Yes, they might be 'force-removing dependencies', 'installing programs' and doing lots of other stuff, but I'd like to know how they're doing it.

Looking into the source code seems the right thing to do then, but where am I supposed to get it from?

I suppose they'll be written in C?

EDIT: I'm not talking about packages installed using apt-get. I'm looking for the source code of linux/unix commands.

TellMeWhy
  • 17,484
  • Do you even search? ;) – kos Jan 04 '16 at 16:03
  • I'm not talking about packages installed with dpkg or apt-get, I'm talking about unix commands... – TellMeWhy Jan 04 '16 at 16:04
  • Then it's too broad / unclear, which Linux commands? There are tons of them, mantained by tons of different mantainers. apt-get source always avails since you can download the packages which provide them and look at their source code from there. – kos Jan 04 '16 at 16:11
  • So the commands are installed by apt-get? – TellMeWhy Jan 04 '16 at 16:12
  • 1
    Absolutely, the most common ones for example are provided by coreutils. – kos Jan 04 '16 at 16:16
  • I don't get the point of this at all. You want source code for commands you run in apt? Commands don't have there own source code they manipulate programs and will be defined in that programs source code. Please do correct me if i am wrong or missing the point.. – Mark Kirby Jan 04 '16 at 16:17
  • @markkirby I want source code for linux commands. Any command. – TellMeWhy Jan 04 '16 at 16:18
  • You need to understand something: let's say that you want the source code for rm. That's hosted at gnu.org. Then let's say that you want the source code for Perl. That's hosted at perl.org. Can you see the problem with that? We can't put all the links to any known command's mantainer in an answer. The closest you can get to a unique place to get the source code for a command is downloading the package that provides it from the repositories. Other than that the answer is just: it depends on the command, visit the mantainer's website. – kos Jan 04 '16 at 16:38
  • @kos Thanx kos - could you give an answer that sums it all up? – TellMeWhy Jan 04 '16 at 16:40
  • 2
    The question as is phrased is off-topic and too broad: "Linux commands" doesn't necessarily pertain to Ubuntu, and the only answer to that would be "visit the command mantainer's website". And to be honest that wouldn't be a great question either. If you're happy with narrowing it down to "Ubuntu's commands" then the question would be fine, but than it would have been answered already in the duplicate I linked. I don't see a way out of this honestly. – kos Jan 04 '16 at 17:02
  • What do you mean? – kos Jan 04 '16 at 17:06
  • Lol, nvm - I tried closing the question myself, but for some reason, it's just counting it as a vote. – TellMeWhy Jan 04 '16 at 17:07
  • You should have a button with "That solved my problem!" written on it at the top of the question's body, like this. Isn't it there? – kos Jan 04 '16 at 17:12
  • No, since I edited my answer to "explain why"... – TellMeWhy Jan 04 '16 at 17:14
  • 1
    Alright, it doesn't matter, it will be closed by someone else. :) – kos Jan 04 '16 at 17:16

2 Answers2

4

Syntax: apt-get source command-name

Example: apt-get source netstat

If it cannot find:

Add a Source URI to sources.lst

cat /etc/apt/sources.list

deb-src http://ftp.de.debian.org/debian lenny main

apt-get update

Olimjon
  • 7,292
3

I think you're talking about GNU/Debian commands. Linux does not have commands. Most Linux distributions use GNU utilities (that's why we should call them 'GNU/Linux') and their own commands (such as Debian's APT system). For example, in Ubuntu, commands such as cp, cd, mv are part of the GNU Core Utilities, which are part of the Ubuntu core (base) system. They are represented by the package coreutils. There is an apt-get paramater that you can use to get packages source code: apt-get source. To get coreutils' source code, use sudo apt-get source coreutils. It's important to know that commands are nothing more than binaries placed in the paths of the PATH environment variable. These binaries are usually written in C. Also note that commands from some other Unix-like systems, even though they have the same names, are not from the GNU project and sometimes have different syntax. This is the case with the BSD's (FreeBSD, OpenBSD, NetBSD) and OSX (based in FreeBSD).

Eduardo Cola
  • 5,817