7

I am trying to create symbolic link as below:

ln -s /home/scripts/logs  /home/log 

The directory /home/log is already existing, which can't be deleted. When I do this it creates the symbolic link as /home/log/logs. I know that if the target is a directory and it already exists ln -s will create a sub-folder of source inside target directory. But I just want the contents of my source directory /home/scripts/logs/test_contents to be in target /home/log/test_contents.

Is there any solution for this?

Note: I can't remove /home/logs which contains logs of other applications

1
  • 1
    Do it the other way around? Delete /home/scripts/logs and make it a link to /home/log? Commented Nov 21, 2019 at 7:30

2 Answers 2

20

You have your ln -s command backwards. The first operand is where you want the link to point, and the second is what you want to call the symbolic link itself.

You can remember the order of the operands with the command ln -s this here and read it as "Take this and create a symbolic link for it here" (just like mv this here is "Take this and move it here", etc.)

The command

ln -s /home/logs /home/scripts/logs

would create the symbolic link /home/scripts/logs pointing to /home/logs (assuming /home/scripts/logs is not already existing).

In real life, you probably aren't working with directories directly beneath /home though, so it's likely that you actually want

ln -s "$HOME/logs" "$HOME/scripts/logs"

... or something similar.

2
  • While this and here are helpful, a similar answer uses real_folder (comes before) and link_folder (comes after) which I find more intuitive: askubuntu.com/a/214650/1008445 Commented May 7 at 13:05
  • @abhishek47 The point I’m making in that part of the text is that the order of arguments is the same as for mv and other similar standard commands. The ln utility obviously also works on files, not just directories. Commented May 7 at 13:11
3

It seems you want to symlink the files in your directory, not the directory itself. Then you probably want this:

ln -s /home/scripts/logs/*  /home/log/
3
  • 4
    That'd work for all files currently in /home/scripts/logs/ but not any that are created later. I'm not sure that's what he wants. Commented Nov 21, 2019 at 8:03
  • @Petr Tesařík i need to create symlink for the directory so all the files created later will be present in /home/log Commented Nov 21, 2019 at 8:20
  • @xaglez Hm, so, what should happen to the original content of your target directory? Do you expect some magic that merges the content of the original directory with the directory you're linking? Commented Nov 21, 2019 at 19:45

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.