Puzzled with hexdump, hd and ln

How to create a symbolic link to a command with certain argument?

When I man hexdump, it is said in the man page that "-C Canonical hex+ASCII display...Calling the command hd implies this option". Actually it is. hd equals to hexdump -C.

And then I examined the ln command but find it is a symbolic link to hexdump, just like this: /usr/bin/hd -> hexdump.

But I failed to make such a symbolic link like this. I tried: ln -s "/bin/ls -al" myls. But it didn't work.

I wonder how to make a symbolic link to a command with certain argument.

Thanks.

Short answer: you can't

Long answer: A symbolic link is just a reference to a different file. Basically it tells the OS "You were looking for file x, but to use it please load file y". However, since every program is told it's execution name as the very first parameter (even before those you specify on the command line), it can use different behaviour based on that name. But the program itself has to support that, and short of modifying the source you can't change the behaviour.

What you can do instead is create an alias:

alias myls="/bin/ls -la"
1 Like

Additional you can only like this so you cant not set options with command because this change the directive and there is no `ls -la`

# ln -s "/bin/ls" myls
# ./myls
1 Like

@pludi:

Thank you. That's interesting. I notice that the utility BusyBox behaves in the way you mentioned.

lrwxrwxrwx    1 1004     1004            7 Jan  1 00:00 chgrp -> busybox
lrwxrwxrwx    1 1004     1004            7 Jan  1 00:00 chmod -> busybox
lrwxrwxrwx    1 1004     1004            7 Jan  1 00:00 chown -> busybox
lrwxrwxrwx    1 1004     1004            7 Jan  1 00:00 cp -> busybox

But, does the ln command have nothing to do with this feature? Is it only a trick of the program linked?

No, the ln command has nothing to do with it. The only thing it really does is call the symlink or link function, plus some validation. After all, a program is just a file, like a text file or image.

It does, and it doesn't. Busybox can detect what name it's called with and act accordingly; a trick its developers exploited to squeeze dozens of utilities into one medium executable. What you don't see happening is any arguments in those links. As described previously, that has to be done in the shell.