-1

I am new to Linx.

I have a file oops.c in /home/tuna/objects directory.

I wanted to create a symbolic link for above file in /home/tuna/myfolder .

I tried cd /home/tuna/myfolde $: ln -s /home/tuna/objects/oops.c oops.c

And when i open the link, its empty. I want to have the link same as original file .

Please help

0

3 Answers 3

2

I would do ls to see if it is correctly linked to the file.

Type ls -l and see the list of files in your /home/tuna/myfolder directory. You should see something like:

lrwxrwxrwx 1 tuna None xx Sep 16 12:00 oops.c -> /home/tuna/objects/oops.c

if you don't see something like this, you may want to try again with full path. like:

ln -s /home/tuna/objects/oops.c /home/tuna/myfolder/oops.c

1
ln -s /path/to/file /path/to/symlink

so in your case

ln -s /home/tuna/objects/oops.c /home/tuna/myfolde/oops.c
5
  • Symbolic link is more like a shortcut. If you move the target file, then you need to recreate.
    – Srini V
    Sep 16, 2013 at 19:58
  • by default the link will be created in the current directory. So what you propose in the answer is not OP's problem. Sep 16, 2013 at 20:00
  • The symbolic link still opens an empty file in myfolder folder Sep 16, 2013 at 20:01
  • OK. Check for the content, permission of the file. If the link is dead then it would open a empty file.
    – Srini V
    Sep 16, 2013 at 20:03
  • Is your issue resolved? If so could you please post the reply on what went wrong?
    – Srini V
    Sep 16, 2013 at 20:17
0

The simplest form of ln is this to create a symlink:

cd /home/tuna/myfolder
ln -s /home/tuna/objects/oops.c
cat oops.c     # This will print the file

What exactly do you mean when you say "when I look it is empty"?

An extract from ln's man page, just to clarify things:

   ln [OPTION]... [-T] TARGET LINK_NAME   (1st form)
   ln [OPTION]... TARGET                  (2nd form)
   ln [OPTION]... TARGET... DIRECTORY     (3rd form)
   ln [OPTION]... -t DIRECTORY TARGET...  (4th form)

Your original code is the 3rd form which tries to create a symlink to /home/tune/objects/oops.c in the folder oops.c. You should use the 2nd form which creates a symlink called oops.c in the current folder, pointing to home/tuna/objects/oops.c.

0

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