I had installed Ubuntu 14.04 on virtualbox, I need to be able to read source code of shell commands, and modify any command? any help please? where i can find the shell commands? in which directory?

  • 1
    Ubuntu is open source. Add the source repositories and down-load any sources you want. Use the type command to find out where any given command resides. Add -a if you want to find every instance of a command. – AFH Oct 21 '14 at 21:42
  • The apt package manager will get you the source of any package on the system, and build it for you. – Chris Stratton Oct 21 '14 at 22:39

Different shell commands will come from different places, however the following procedure is likely to work for a great many of them:

(Note: You do not need to be root for any of this.)

  1. Figure out where the command file resides, e.g. to find which, try type which in your bash shell, or even which which (more generally, which ..., where ... represents whatever command you wish to find).
  2. Next, you'll want to see what package normally provides this. dpkg -S /path/name can get you this, or, to combine steps 1 and 2: dpkg -S $(which ...), e.g. dpkg -S $(which which). In this case, I get: debianutils: /usr/bin/which
  3. Finally, you want to grab the actual source. (Note: You may need to run apt-get update before doing this, especially if you get an error like E: You must put some 'source' URIs in your sources.list, which appears, at least in my case, to be a bit of a red-herring error message.) This can be done with apt-get source ..., e.g. apt-get source debianutils (one could combine steps and do apt-get source $(dpkg -S $(which which) | cut -d: -f1)).

From there, you should have some new files and directories in whatever directory you started in (so start in an appropriate directory), containing the appropriate source.

Another example, in one-liner form:

cmd_to_get=ls; apt-get source $(dpkg -S $(which $cmd_to_get) | cut -d: -f1)

that grabs the source for ls (along with a bunch of other stuff that's in coreutils along with it).

From there, you can play around further.

If you'd like to then build things, see this related question on askubuntu.

Happy hacking!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.