Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to put symbolic link into a file?

If you look at the image, there is a file called "sh" and it looks like have a link to bash file. How can I make a link like this one?

I tried ln -s original_file destination_file

but, it didn't work.

enter image description here

share|improve this question

migrated from Nov 12 '12 at 12:32

This question came from our site for professional and enthusiast programmers.

A symbolic link is not 'inside a file', it is an inode inside the file system by itself, just like a file is. And yes, ln -s is what is typically used to create such links. What do you mean by "didn't work" and why is this flagged as "ssh"? – arkascha Nov 12 '12 at 11:19
Make sure your original_file exist and that you have write access to the place you want to put the link. as above, what did you mean by "didn't work" - that the link did not show up or that the link did not point where you wanted it to be? If you try to link to a file in another directory, it is often best to go to the directory you want the link to be in when you make the link. – MortenSickel Nov 12 '12 at 11:23

The syntax for ln is:

ln -sf <link TARGET> <link NAME>

for a file link, or without the -f option for a directory link (though ln is pretty smart at working out what to use based on what you tell it.

So, to create the link you've pointed out in your screen shot, I would pass:

ln -sfv /bin/bash /bin/sh

I pass here -s (symbolic) -f (file) and -v (verbose, prints out the result of the command).

I'd expect this to output something like:

ln: /bin/sh -> /bin/bash

or if I wasn't root, of course, a permission denied notice. Be very careful, however, if your link name already exists as a file on the system - I have in the past mixed the syntax up and overwritten a file by accident.

share|improve this answer
-f means "force" - without -f ln will not owerwrite existing file with the link if file with same name exists. – x22 Nov 12 '12 at 13:12
Huh. I wonder where I misread that then... – Xyon Nov 12 '12 at 14:05

You must log in to answer this question.