最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the difference between fs.link and fs.symlink? Are they platform independent? - Stack Overflow

programmeradmin2浏览0评论

What is the difference between fs.link and fs.symlink?

I want to programmatically create a symbolic link to a physical file (or another symlink), and I'm on Linux, but wondered if it was possible to write a OS independant solution? What are the limitations?

Update

From the given answers and comments, Windows seems to support it.

What is the difference between fs.link and fs.symlink?

I want to programmatically create a symbolic link to a physical file (or another symlink), and I'm on Linux, but wondered if it was possible to write a OS independant solution? What are the limitations?

Update

From the given answers and comments, Windows seems to support it.

Share Improve this question edited Nov 2, 2014 at 4:13 Paul 27.4k13 gold badges89 silver badges126 bronze badges asked Nov 2, 2014 at 3:26 Yanick RochonYanick Rochon 53.5k29 gold badges145 silver badges223 bronze badges 3
  • The link function is described here: gnu.org/software/libc/manual/html_node/… – Qantas 94 Heavy Commented Nov 2, 2014 at 3:30
  • this is possible if fs.symlink wraps the creation of aliases in OS X, shortcuts in Windoze, and symlinks in GNU / Linux, which is likely. – code_monk Commented Nov 2, 2014 at 3:55
  • 2 SO has become such a place that, even an original, not opinionated, and concise question gets downvotes without explanations. Sheessh. I don't really care the the downvotes, but at least comment :) – Yanick Rochon Commented Nov 2, 2014 at 4:13
Add a comment  | 

1 Answer 1

Reset to default 24

Linux systems have two kinds of links, hard and soft.

fs.link() is creating hard links through the C system call link(). From a terminal the equivalent is ln originalName linkName. A hard link consists of a new directory entry referencing the same file. In listings it appears to be an ordinary file, just like the original file. If the original file is removed, the content is not removed, and the hard link still works. The area of the disk is only freed when all hard links are deleted.

fs.symlink() is creating soft links, a.k.a symbolic links through the C system call symlink(). From a terminal the equivalent is ln -s originalName linkName where the -s tag denotes a soft/symbolic link. A soft link creates a special kind of directory entry that points to another file. The fact that it is a pointer is obvious when listing it, and deleting the original is sufficient to delete the content, and disrupts using the link.

I don't code on MS Windows, but this guide on symbolic links indicates that there is a mklink command for Windows command shell that can create either a hard (mklink /H) or a soft (mklink /D) link. Microsoft Developer's Network -- MSDN -- has entries for system functions CreateSymbolicLink and CreateHardLink which may provide more information about what is happening at a lower level.

On Mac, developer.apple.com's page for ln shows they have the BSD version of the ln link creation terminal command in Mac OSX 10.9, supporting both hard and soft links.

发布评论

评论列表(0)

  1. 暂无评论