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.

Can anybody give me an example why should we use the symlink kind of the "ln" command between files? I know that when you create symlink file, that file size is very small and it redirect to the main file.

The problem is when I created the symlink from a specific file (text file) from another directory, but I can't cat, less or any kind of print and view that file. Pls help me understand more about this type.

Thanks.

share|improve this question
1  
It would help if you post the precise command(s) you typed. I suspect a path error. –  jlliagre Jul 26 '13 at 18:29
add comment

3 Answers 3

up vote 0 down vote accepted

Let say you have a file named /home/george/Images/ubuntu.jpg and you want it to be available too in the /var/tmp directory, you can run:

ln -s /home/george/Images/ubuntu.jpg /var/tmp

Then, you can equally view the file using the /var/tmp/ubuntu.jpg path.

Beware not to miss to provide a correct relative or absolute path for the first parameter passed to the link command. This path is relative to the directory where the symbolic link resides. This is a common source of mistakes, like Nitin reply demonstrates.

share|improve this answer
    
That's great. Now I understand it. That's just my typing problem haha. Thanks dude! –  George Luong Jul 27 '13 at 15:56
add comment

Symbolic links contains a text string that is automatically interpreted and followed by the operating system as a path to a target file or directory.

The most relevant use case of symbolic links is restructuring of file system hierarchy, so keeping the compatibility with old tools and standards like POSIX.

Wikipedia has extensive information on symbolic links.

share|improve this answer
add comment

As you mentioned that you have created a link but cannot access the file if you do cat.

  1. You should have permission to cat original file.
  2. File should be on same file-system/partition.

-------------------------- 
Example: 
$ cd / 
$ echo "UBUNTU" > orig.txt 
$ cat orig.txt 
UBUNTU 
$ ls -l orig.txt
-rw-r--r--   1 root     root           0 Jul 26 18:28 orig.txt 
$ ln -s orig.txt /pool0/manager/link.txt 
$ cd /pool0/manager/ 
$ cat link.txt
 cat: cannot open link.txt: No such file or directory

--------------------------

share|improve this answer
    
Your command created a wrong symbolic link, i.e. you linked /pool0/manager/orig.txt to /pool0/manager/link.txt. The first file doesn't exist. This has nothing to do with the same file-system limitation that doesn't affect symbolic links anyway. –  jlliagre Jul 26 '13 at 18:32
    
file orig.txt lies in / while symlink lies in other partition /pool0/manager/link.txt which i tested. –  Nitin Jul 26 '13 at 18:51
    
As you wrote the command, orig.txt is in the same partition, but doesn't exist. –  jlliagre Jul 26 '13 at 19:12
    
You should have typed: ln -s /orig.txt /pool0/manager/link.txt (notice the absolute path for /orig.txt. –  jlliagre Jul 26 '13 at 19:19
    
Thanks for your test Nitin! That's just my typing problem... Haha. –  George Luong Jul 27 '13 at 15:57
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.