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?
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.)
- Figure out where the command file resides, e.g. to find
type whichin your bash shell, or even
which which(more generally,
which ..., where
...represents whatever command you wish to find).
- Next, you'll want to see what package normally provides this.
dpkg -S /path/namecan get you this, or, to combine steps 1 and 2:
dpkg -S $(which ...), e.g.
dpkg -S $(which which). In this case, I get:
- Finally, you want to grab the actual source. (Note: You may need to run
apt-get updatebefore 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.