9

So I have created a bunch of symbolic links to top of source code tree, data directories, etc

How do I, from command line, cd to these links?

11

Are you sure you actually created symbolic links, or did you create a Windows Shortcut? Those are not links, and don't work as such. Actual symbolic links behave like other directories, so if you are unable to cd into it, either you a) don't have permissions to enter the target directory, b) the symlink doesn't point to a valid directory, or c) it's actually not a symlink.

(If you want to create NTFS symlinks, use the MKLINK command)


As a parable, imagine a river and its tributaries: all those rivers flow into the large river; that is the directory structure; riverside towns are files. Now, a Windows Shortcut is just a sign on the riverbank: "it's not here, you need to go back down to Mississippi and then up Ohio, it is five miles upstream, on the left bank" - but you need to read English to understand it (have a program which handles this for you, e.g. Explorer.exe). A symlink is like a water canal: if you follow it, it will actually take you someplace else, no matter whether you can read English or not (no matter what program you use).

8
  • same thing as downloads folder shortcut? I thought that is the way you create a symbolic link in Windows 7 – reza Jun 15 '11 at 15:49
  • 2
    shortcut != symbolic link : "shortcuts" are just regular files with content "see that other thing over there", and they are handled by the shell (Explorer.exe, pretty much a normal program). "symbolic links" are special data structures in the NTFS structure, which make a directory accessible from an alternate location; they are handled internally, rather deep in the OS. – Piskvor left the building Jun 15 '11 at 15:51
  • No; shortcuts are not symlinks. – SLaks Jun 15 '11 at 15:51
  • @reza: As to "how to create symbolic links in Windows", see that link I posted. – Piskvor left the building Jun 15 '11 at 15:56
  • 1
    @Piskvor Yeah sure, but there is no point in using it, as it cannot make symbolic links, so has less functionality than mklink, which is installed by default. – paradroid Jan 21 '16 at 18:48
0

Symbolic links are normal directories.
You can CD into them just like any other directory.

5
  • I have a link called: code – reza Jun 15 '11 at 15:43
  • I have a link called: code, you are saying just type cd code. If that is what you are saying, it is not working. – reza Jun 15 '11 at 15:43
  • Why not? What happens? – SLaks Jun 15 '11 at 15:44
  • 2
    Are you sure you aren't talking about shortcuts? – SLaks Jun 15 '11 at 15:44
  • 1
    the error is the same as any non existent path. System can not find the path specified is the error – reza Jun 15 '11 at 15:48
0

Example: Target folder is d:\code\ , I made a shortcut (rightclick-drag-drop) to it in C:\

see snapshot: enter image description here

The 'shortcut' is an .lnk file which has the target path (D:\code)and a bunch of other junk in it ie. computer name (kandalf) and god knows what else.

You could parse the .lnk file and use the path inside it.
Google for 'parse .lnk file ' (in C/VB/Whatever you preffer) or '.lnk file format'

Too much trouble? why not use full paths in your config file/whatever it is you're doing? ;)

As a last resort I'd go for NTFS Junctions... Last resort because, the windows file manager is stupid, ie. when you delete a junction it doesn't just delete the junction; it deletes the junction AND the target folder and all it's files! Now think of that junction sitting under a deep directory structure in an obscure folder that you later want to delete -- yup you guessed it!

1
  • @DMB: Explorer in Vista and newer are junction-aware. Deleting a junction will only delete the junction itself, not the target. – afrazier Jun 15 '11 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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