What is the windows equivalent to the ln -s

2019-04-09 02:22发布

问题:

I'm attempting to follow the following tutorial for creating a program environment for the Twilio and App Engine library.

https://developers.google.com/appengine/articles/twilio

I'm good up until the point it says:

Link the Twilio library and its dependencies into your project:

$ ln -s venv/lib/python2.7/site-packages/twilio .

$ ln -s venv/lib/python2.7/site-packages/httplib2 .

$ ln -s venv/lib/python2.7/site-packages/six.py .

I've researched and it appears I'll be using something along the lines of

mklink /d venv\lib\python2.7\site-packages\twilio .

if I've understood correctly I basically need to understand what the "." stands for, as that is the target of the symbolic link? (Not certain about that.)

I'm using cmd.exe for the shell and could really use the help of someone that understands Unix better than I.

EDIT:

After reviewing my directory the path after venv is venv\lib\site-packages. There are already folders for Twilio and httplib2 at that point of the directory. Six exists at that point in a file named six.py.

Is the intent of the Unix command that I create a symbolic link from those existing folders to the working directory? Because what its doing is telling me I can't create existing files for both Twilio and httplib2. (There are already folders in the venv\lib\site-packages directory, and it WILL let me do a symlink for six, but then it recursively creates 4500 more layers deep of the entire six folder.)

回答1:

Try this :

mklink /D .\ venv\lib\python2.7\site-packages\httplib2

Note : mklink [OPTION] LINK TARGET (link and target are flipped compared to linux's ln -s)

Mklink Command Syntax :

MKLINK has 3 options /D, /H and /J. You also need to specify the path to the new symbolic link and the path to the original file or directory.

/D – used to create symbolic links for directories (d for directory)

/H – used to create hard links (h for hard link)

/J – used to create directory junction (j for junction)

By the way, always prefer mklink /D over mklink /J. Windows explorer will delete the entire contents of a junction (the latter) whereas when deleting a directory link (the former) it will just remove the link.

The dot . is the current directory (from where you are running the command). In the example above, I changed it to .\ to make it explicit.

For files : Helpful link.

If you can't get privilege with /D, use a hard link (option /H) :

mklink /H .\six.py venv\lib\python2.7\site-packages\six.py


回答2:

'.' stands for the current folder, in both *nix-land and Windows. So those commands are making symbolic links right then and there.
These would be the same as saying:

ln -s venv/lib/python2.7/site-packages/twilio twilio

Or in Windows (Vista, 7, 2008 and up):

mklink /d twilio venv\lib\python2.7\site-packages\twilio 

where

  • twilio is the target or link to create
  • venv\lib\python2.7\site-packages\twilio is the source directory

Remember that mklink has the opposite soure | target syntax that ln -s has.

ln is source -> target
mklink is target -> source