-1

My problem is that I need to move from a directory to another one by only using the ln command

So here I have this relative path: ../../10/wsl and I know I have to create a symlink with ln to be able to create a tunnel to the other directory. Then I will be able to use cd to move.

I tried

  • ln -s filepath
  • ln -rs filepath

but nothing works

terdon
  • 242,166
  • 1
    It's not clear what you mean. If you want to move to another directory, use cd. If you want to create a symbolic link, use ln -s target link_name, man ln for more. – thanasisp Oct 26 '20 at 03:31
  • Are you on Linux? Which one? Your file is "wsl", does this mean you're actually using Windows with WSL? – terdon Oct 26 '20 at 09:55

2 Answers2

0

Does this example help you? I just did this a few hours ago.

Iwantthefiletogohere Thefiletobemovedishere

ln -s /home/orca/Downloads/Thefiletobemovedishere/sixfigureseminarmap.pdf /home/orca/Downloads/Iwantthefiletogohere
0

man ln shows:

NAME
      ln - make links between files

SYNOPSIS ln [OPTION]... [-T] TARGET LINK_NAME ln [OPTION]... TARGET ln [OPTION]... TARGET... DIRECTORY ln [OPTION]... -t DIRECTORY TARGET...

DESCRIPTION In the 1st form, create a link to TARGET with the name LINK_NAME.
In the 2nd form, create a link to TARGET in the current directory. In the 3rd and 4th forms, create links to each TARGET in DIRECTORY. Create hard links by default, symbolic links with --symbolic. By de‐fault, each destination (name of new link) should not already exist. When creating hard links, each TARGET must exist. Symbolic links can hold arbitrary text; if later resolved, a relative link is interpreted in relation to its parent directory.

To make a link using the first form use: ln -s ../../10/wsl wsl. With the second form you should be able to: ln -s ../../10/wsl. Both of these will create ./wsl.

I see you've already tried the second form, therefore these could be some of the problems you ran into:

$ ln ../../10/wsl
ln: ../../10/wsl: hard link not allowed for directory
$ ln -s ../../10/wsl
ln: failed to create symbolic link './wsl': File exists

In the first line, we forgot the -s flag. In the second form, we already had a file in the current directory called ./wsl. We will need to move or delete it if we want this command to work. If these aren't your problems, then post your output for further guidance.

Once you have your ln command, you can try it out:

# The ls command shows the link
$ ls -l
wsl -> ../../10/wsl

You can cd in and out of that directory:

~ $ cd wsl ~/wsl $ cd .. ~ $

If you create a file here, you can also see that file appear in the original directory

$ touch wsl/file1 $ ls ../../10/wsl file1

terdon
  • 242,166
Stewart
  • 13,677