Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is it possible for me to create an ssh session on windows which then does some folder/file manipulation and then creates a NATIVE windows symlink.

i.e. a symlink that will be recognised by IIS and other app/services.

i've tried to create a symlink to a folder but all i get is a 1kb system file (with the same name) where the symlinked folder should be.

using ln -s SOURCE TARGET

i end up with target (system file, 1kb).

BUT in cygwin i can see the symlinked folder as normal.

Spent too much time on this :-)

share|improve this question
add comment

3 Answers 3

up vote 3 down vote accepted

Cygwin has its own symlink file format because native Windows symlinks don't have the right POSIX semantics. Worse, only administrators are allowed to create them.

If you do have administrator rights, cmd /c mklink can give you access to cmd.exe's builtin mklink command from a Cygwin session. Combine with cygpath to add POSIX path support, e.g.:

mklink() { cmd /c mklink "$(cygpath -w $1)" "$(cygpath -w $2)"; }
share|improve this answer
    
This unfortunately does not work in MinGW (e.g. the Git Bash Shell)... not just because of the cygpath bits but because the cmd /c just opens a CMD.EXE shell and leaves you there. Too bad, it's a clever trick! –  iconoclast Sep 6 '13 at 21:42
add comment

What you are looking for is called a junction in the Windows world. You can find a tool in the Sysinternals suite from Microsoft to do that, more precisely: http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx.

I know it is possible with folders but I don't think it applies to files, moreover it is not possible to create juntions of remote shares.

share|improve this answer
    
yeah, i'm aware of making the mklink calls on windows. i've tried to use a bat file with that, but then you get in to path issues etc. where unix style paths are different. it all starts to get messy. was hoping i could just make a call to cygwin and it translate that to a native symlink –  mickdelaney Sep 24 '10 at 15:05
    
This kind of links are implemented at file system level so you are tight to what, in your case probably NTFS, is offering. –  Cristian Sep 24 '10 at 15:22
add comment

Inspired by serverfault.com/a/184462

This should work with files and directories

mklink(){
  mapfile -t a < <(cygpath -aw "$@")
  [ -d "$2" ] && d=/d || d=
  cmd /c mklink $d "${a[@]}"
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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