8

I have a shortcut to a folder on my Desktop (as I don't store files directly on it). Is it possible to get to the directory the shortcut points to when I am in the desktop on command line?

I would like to know if it's possible in Windows as well as Unix-based OS.

2

3 Answers 3

10

Yes, this is possible on Windows. You need to make directory symlinks. Try out the following commands as an example:

> cd %userprofile%
> mklink /D OMGDOCUMENTS Documents
> cd OMGDOCUMENTS
> dir

You'll notice that the contents of \OMGDOCUMENTS are the same as \Documents. If you then go back to the parent folder %userprofile% and run the dir command, you'll see that your \OMGDOCUMENTS folder will show up as a symlink.

1
  • When you do the cd command line, it doesn't work with the created link..
    – nonozor
    Jun 16, 2022 at 8:13
2

See Windows 7 and cd to symbolic links - long and short, if you have an actual symbolic link, it should work as you'd expect. If you just have a shortcut (*.lnk file), those aren't links and won't do what you're wanting.

As far as Linux goes:

username@hostname ~ $ mkdir /home/username/test     # make new directory
username@hostname ~ $ touch /home/username/test/somefile    # make a file in directory
username@hostname ~ $ cd /tmp   # changing to temp folder
username@hostname /tmp $ ln -s /home/username/test testlink # make a link to the folder made previously
username@hostname /tmp $ ls -la test*   # test to show the link connects to the folder I made
lrwxrwxrwx 1 username username 18 Jun 23 11:49 testlink -> /home/username/test
username@hostname /tmp $ cd testlink    # can we traverse into the link?
username@hostname /tmp/testlink $ ls -la    # testing...
-rw-r--r--  1 username username    0 Jun 23 11:49 somefile  # We can!
0

So via properties you can see the path that the shortcut.lnk is pointing to and run your command pointing to that path. So to access the path you would type the shortcut name in quotes. such as:

C:\Users\Marsha\Desktop>"test.lnk"

Also refer to the following Stack link: How to Execute ShortCut From Command line in Windows 7

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .