Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to create a symbolic link with ln -s old.file new.file but ln seems to stubbornly create hardlinks instead. For instance, when I move the link to another folder, it becomes broken. What's happening here really? Am I missing something?

Edit:

Output of ls -li before creating link:

total 624
8536495 lrwxrwxrwx 1 benjamin benjamin     59 2011-08-14 14:21 alarm.wav -> /home/benjamin/.config/cairo-dock/third-party/Gmail/hit.wav
8536499 -rw-r--r-- 1 benjamin benjamin    663 2011-08-14 14:31 auto-load.conf
7344051 -rw-r--r-- 1 benjamin benjamin  49708 2011-08-14 14:02 drip.wav
8536261 -rw-r--r-- 1 benjamin benjamin  26313 2011-08-14 13:24 error.svg
7344049 -rw-r--r-- 1 benjamin benjamin 267820 2011-08-14 14:02 glass.wav
8536267 -rw-r--r-- 1 benjamin benjamin   3664 2011-08-15 22:05 Gmail.conf
8526370 -rwxr-xr-x 1 benjamin benjamin  15224 2011-08-23 11:21 Gmail.py
7344046 -rw-r--r-- 1 benjamin benjamin  11052 2011-08-14 14:21 hit.wav
8536293 -rw-r--r-- 1 benjamin benjamin  24153 2011-05-26 16:17 icon
9186712 drwxr-xr-x 3 benjamin benjamin   4096 2011-08-13 15:35 nbproject
7344050 -rw-r--r-- 1 benjamin benjamin 113196 2011-08-14 14:02 pop.wav
8536418 -rw-r--r-- 1 benjamin benjamin  10762 2011-08-14 14:24 preview
7344048 -rw-r--r-- 1 benjamin benjamin  44844 2011-08-14 14:02 stick.wav
8536286 -rw-r--r-- 1 benjamin benjamin  23848 2011-08-14 13:32 SVGmaker.py
8536304 -rw-r--r-- 1 benjamin benjamin  22662 2011-08-14 13:32 SVGmaker.pyc

Then command ran is ln -s Gmail.py Gmail

After running that command, ls -li returns:

total 624
8536495 lrwxrwxrwx 1 benjamin benjamin     59 2011-08-14 14:21 alarm.wav -> /home/benjamin/.config/cairo-dock/third-party/Gmail/hit.wav
8536499 -rw-r--r-- 1 benjamin benjamin    663 2011-08-14 14:31 auto-load.conf
7344051 -rw-r--r-- 1 benjamin benjamin  49708 2011-08-14 14:02 drip.wav
8536261 -rw-r--r-- 1 benjamin benjamin  26313 2011-08-14 13:24 error.svg
7344049 -rw-r--r-- 1 benjamin benjamin 267820 2011-08-14 14:02 glass.wav
8519869 lrwxrwxrwx 1 benjamin benjamin      8 2011-08-23 11:27 Gmail -> Gmail.py
8536267 -rw-r--r-- 1 benjamin benjamin   3664 2011-08-15 22:05 Gmail.conf
8526370 -rwxr-xr-x 1 benjamin benjamin  15224 2011-08-23 11:21 Gmail.py
7344046 -rw-r--r-- 1 benjamin benjamin  11052 2011-08-14 14:21 hit.wav
8536293 -rw-r--r-- 1 benjamin benjamin  24153 2011-05-26 16:17 icon
9186712 drwxr-xr-x 3 benjamin benjamin   4096 2011-08-13 15:35 nbproject
7344050 -rw-r--r-- 1 benjamin benjamin 113196 2011-08-14 14:02 pop.wav
8536418 -rw-r--r-- 1 benjamin benjamin  10762 2011-08-14 14:24 preview
7344048 -rw-r--r-- 1 benjamin benjamin  44844 2011-08-14 14:02 stick.wav
8536286 -rw-r--r-- 1 benjamin benjamin  23848 2011-08-14 13:32 SVGmaker.py
8536304 -rw-r--r-- 1 benjamin benjamin  22662 2011-08-14 13:32 SVGmaker.pyc
share|improve this question
    
The same way you check whether mv moved a file or printed it 10,000 times :) –  SpashHit Aug 23 '11 at 13:52
add comment

3 Answers

up vote 8 down vote accepted

The link you created is symbolic, not hard, as you see from the different inodes numbers, and from the representation with an arrow -> in ls output.

The inode is a number representing a sequence of block on the filesystem. You see it in the first column of the output, because we used the -i option to ls. Different inode means different files. Same inode with different names means same storage on disk but accessible from different names (and places).

You cannot reliably move a symlink created with a relative path. Create it with

ln -s /path/to/Gmail.py Gmail

A symlink essentially contains a string representing a path. If the path exist on the other machine, it will point to that same path on the other machine, and this can or cannot be what you want.

share|improve this answer
add comment

It is not a hard link. In that a hard link will point to the same file inode. Here your inode are the numbers at the beginning of the listing from ls.

8526370 Gmail.py
8519869 Gmail

8526370 -rwxr-xr-x 1 benjamin benjamin  15224 2011-08-23 11:21 Gmail.py
8519869 lrwxrwxrwx 1 benjamin benjamin      8 2011-08-23 11:27 Gmail -> Gmail.py

Here is a hard link and a symbolic I created

$ touch link1 link2  
$ sudo ln link1 link1.lk # hard link  
$ sudo ln -s link2 link2.lk # symbolic link  

Executing ll -li link*

160889 -rw-r--r-- 2 aaron aaron 0 2011-08-23 12:59 link1
160889 -rw-r--r-- 2 aaron aaron 0 2011-08-23 12:59 link1.lk
160920 -rw-r--r-- 1 aaron aaron 0 2011-08-23 12:59 link2
128367 lrwxrwxrwx 1 root  root  5 2011-08-23 13:03 link2.lk -> link2

There you can see that both link1 and link1.lk have the same inode number 160889. This is a hard link.

Where as the link2 160920 and link2.lk 128367 have different inode numbers. They are symbolic links.

share|improve this answer
    
I was searching an almost unrelated issue, but I am so glad I found this. You have explained and shown the differences better than I have ever seen.. thank you for this, I think I finally, truly, get it. –  SgtPooki Jan 30 at 20:49
add comment

The link you created is a soft link not a hard link. It is clear from the output of ls which shows

Gmail -> Gmail.py

You can not move it to other location because you are using a relative path to create the link. If you want to be able to move the link to anywhere you want, use absolute path of source. i.e

ln -s /absolute/path/of/Gmail.py Gmail

Now you can move symlink file Gmail to anywhere you want

share|improve this answer
    
Thanks. Now suppose I create a symlink with absolute path: will the link still work on someone else's machine or will the link show my home/username/ instead? –  Benjamin Aug 23 '11 at 10:46
1  
A symlink essentially contains a string representing a path. If the path exist on the other machine, it will point to that same path on the other machine, and this can or cannot be what you want. –  enzotib Aug 23 '11 at 10:51
    
@Benjamin: like enzotib said, a symbolic link merely contains a string which is a path to some other file. So if you move it to another machine, the string contents of the symbolic link will not change. Simply speaking, the link will still show your /home/username. –  binW Aug 23 '11 at 11:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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