On my Android emulator, the /system/bin folder contains several symlinks that point to the toolbox binary:

# ls -l /system/bin
ls -l /system/bin
lrwxr-xr-x root     shell             2012-08-23 07:01 ls -> toolbox
lrwxr-xr-x root     shell             2012-08-23 07:01 lsmod -> toolbox
lrwxr-xr-x root     shell             2012-08-23 07:01 lsof -> toolbox
-rwxr-xr-x root     shell      181002 2012-08-23 07:01 toolbox

My understanding is that 'toolbox' is a binary that is able to do everything that ls, lsmod, lsof etc... can do, and that calling 'ls -l' ends up calling 'toolbox ls -l'.

But what I don't understand is how this works: if 'ls' is indeed a symlink to 'toolbox', then 'ls -l' would become 'toolbox -l', which of course doesn't work.

What am I missing ? (or said differently: what makes 'ls -l' become 'toolbox ls -l' ?)


What you're missing is: The application (in your case toolbox) can evaluate how it was called. To make an easy Linux-example: Say you have a script called myscript, and call it with the parameters para1 para2 (i.e. myscript para1 para2), and the script has a line:

echo $0 $1 $1

It would output exactly what you called it: myscript para1 para2. Now make a symlink: ln -s myscript mylink, call mylink para1 para2, and guess what it will "echo": the command line you called. So parsing the command line, based on the symlink your toolbox was called by, it can determine which functionality you were pointing at.

  • OK, now I get what I was really missing: I was thinking that when calling mylink para1, then $0 would be equal to "myscript". Of course, it doesn't work that way at all: $0 is equals to "mylink", so the script can indeed know what the context is. Thanks a lot ! – laurent kubaski Nov 19 '12 at 15:32

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.