Link Type (shortcuts, soft links, hard links, symbolic links) files and folders in Windows

Four types of links

There are three types of file links supported in the NTFS file system: hard links, junctions, and symbolic links.

  • Shortcut
  • Soft links
  • Hard links
  • Symbolic link

Shortcut ( Shortcut )

A Shell link is a data object that contains information used to access another object in the Shell’s namespace—that is, any object visible through Windows Explorer. The types of objects that can be accessed through Shell links include files, folders, disk drives, and printers

On Windows at *.lnkend of file, these files are often used to specify a particular location of a file or a directory, highly scalable, desktop shortcut is this kind of.

Link Soft / hard link ( Junction [Link Soft] / Hard Link )

A pithy formula, soft directory, the hard file . In other words, soft links only link to the directory, hard link can only link to the file.

A hard link is the file system representation of a file by which more than one path references a single file in the same volume

A junction (also called a soft link) differs from a hard link in that the storage objects it references are separate directories

Hard link file attributes are synchronized, and A <==> B, B A file is a hard link to the file, then change the properties of A (such as hidden A) synchronizes the changes to the property B, the property changes will sync to A. B

Symbolic link ( Symbolic Link )

A symbolic link is a file-system object that points to another file system object. The object being pointed to is called the target.
Symbolic links are transparent to users; the links appear as normal files or directories, and can be acted upon by the user or application in exactly the same manner.

More powerful symbolic links, can link files and folders. Symbol symbol, this means that you can listen to "chaos finger." Which means do.

It is possible (but not advisable) to create two links that point to each other in a loop, or a link that targets itself. Symbolic links can expose security vulnerabilities in applications that aren’t designed to handle them.

the difference

Type \ Properties Can Link to File You can link to the directory Straddle a disk partition Can point to the target does not exist You can point to the relative directory How to delete
Shortcut can can can can no del file
Hard links can no no no no del file
Soft links no can can can no rd folder
Symbolic link can can can can can rd folder or del file

Command line to create links

First, the shortcut is not created from the command line, create only way to create and call COM interfaces (manually right IShellLink) to create, not to create a script command. This programming has brought some difficulties, because to call the COM interface, not so direct.

Of course, the Internet has compiled exe can create shortcuts http://www.optimumx.com/downloads.html#Shortcut , which also use this COM interface is then used in C ++.

The soft links, hard links, symbolic links that can be ordered mklinkto create.

Syntax
  MKLINK [[/D] | [/H] | [/J]] LinkName Target
Key:
  /D    Create a Directory symbolic link. (default is file)
  /H    Create a hard link instead of a symbolic link.
  /J    Create a Directory Junction.
  LinkName The new symbolic link name.
  Target The path (relative or absolute) that the new link refers to.

Use mklinkrequires administrator privileges, and can not be covered if there is a link with the same name, only delete and then create .

API to create links

Recommended here under this article, there is a football including hard links, symbolic links API of Windows , create a directory soft link of black magic , and COM use shortcuts .
http://www.flexhex.com/docs/articles/hard-links.phtml

Examples

Execute the following script to generate links.

@echo off

set root_path=%userprofile%\link
set app_path=%root_path%\app_1.1.5.235
set readme_path=%app_path%\readme.txt

:: 创建根目录
mkdir %root_path%

:: 创建程序目录
mkdir %app_path%

:: 创建程序目录软链接
mklink /j %root_path%\app_junction %root_path%\..\link\app_1.1.5.235

:: 创建程序目录符号链接
mklink /d %root_path%\app_symbolic %root_path%\..\link\app_1.1.5.235

:: 手动创建程序目录快捷方式 %root_path%\app_shortcut.lnk

:: 创建文件 readme.txt
echo generate link >> %readme_path%

:: 创建文件硬链接
mklink /h %app_path%\readme_hard.txt %readme_path%

:: 创建文件符号链接
mklink %app_path%\readme_symbolic.txt %readme_path%

:: 手动创建文件快捷方式readme.lnk

We can see the following results:

Here Insert Picture Description

Here you can see, in use mklinkwhen creating the link, the target path I have used a relative path, but you can see the target path of a soft link has become an absolute path is calculated, and the target of the symbolic link path or write into the relative path before Similarly, the target path shortcuts and hard links also absolute paths.

reference

Published 299 original articles · won praise 352 · Views 450,000 +

Guess you like

Origin blog.csdn.net/FlushHip/article/details/104685928