How to create a link to a directory

LinuxShellCommand

Linux Problem Overview


How to create a link xxx to /home/jake/doc/test/2000/something/?

Assume the xxx is created under /home/jake and you're currently in /home/jake. When you do cd xxx, you directly go to /home/jake/doc/test/2000/something/.

Linux Solutions


Solution 1 - Linux

Symbolic or soft link (files or directories, more flexible and self documenting)

#     Source                             Link
ln -s /home/jake/doc/test/2000/something /home/jake/xxx

Hard link (files only, less flexible and not self documenting)

#   Source                             Link
ln /home/jake/doc/test/2000/something /home/jake/xxx

More information: man ln


/home/jake/xxx is like a new directory. To avoid "is not a directory: No such file or directory" error, as @trlkly comment, use relative path in the target, that is, using the example:

  1. cd /home/jake/
  2. ln -s /home/jake/doc/test/2000/something xxx

Solution 2 - Linux

you should use :

ln -s /home/jake/doc/test/2000/something xxx

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionread ReadView Question on Stackoverflow
Solution 1 - LinuxtheglauberView Answer on Stackoverflow
Solution 2 - LinuxWiseTechiView Answer on Stackoverflow