Windows中文件和文件夹的链接类型(快捷方式、软链接、硬链接、符号链接)

您所在的位置:网站首页 查找快捷方式的原始文件是什么 Windows中文件和文件夹的链接类型(快捷方式、软链接、硬链接、符号链接)

Windows中文件和文件夹的链接类型(快捷方式、软链接、硬链接、符号链接)

2024-07-14 11:31:54| 来源: 网络整理| 查看: 265

链接四大类型

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

快捷方式软链接硬链接符号链接 快捷方式(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

在Windows上以*.lnk结尾的文件,这类文件通常用于指定某一个文件或某一个目录的位置,可扩展性很强,桌面快捷方式就是这类了。

软链接/硬链接(Junction[Soft link] / Hard link)

一个口诀,软链目录,硬链文件。也就是说,软链接只能链接到目录,硬链接只能链接到文件。

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

硬链接的文件属性是同步的,A B,A文件是B文件的硬链接,那么改动A的属性(比如说隐藏A)会同步改动到B的属性,改动B的属性会同步到A。

符号链接(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.

符号链接比较强大,可链接文件和文件夹。符号符号,听这个意思就是可以”乱指“。指哪都行。

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.

区别 类型\属性能否链接到文件能否链接到目录能否跨越磁盘分区能否指向不存在的目标能否指向相对目录如何删除快捷方式能能能能否del file硬链接能否否否否del file软链接否能能能否rd folder符号链接能能能能能rd folder or del file 命令行创建链接

首先,快捷方式是不能从命令行进行创建的,创建方式只能通过手动右键创建和调用COM接口(IShellLink)创建,不可通过脚本命令来创建。这就对编程带来了一些困难,因为要调用COM接口,不是那么直接。

当然,网上有编译好的exe可以创建快捷方式http://www.optimumx.com/downloads.html#Shortcut,这个里面也是利用COM接口然后使用C++编写的。

而软链接、硬链接、符号链接是可以通过命令mklink来创建的。

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.

使用mklink需要管理员权限,且不能覆盖,如果存在同名链接,只能删除然后再创建。

API创建链接

这里推荐下这篇文章,这里面揽括了硬链接、符号链接的Windows API,创建目录软链接的黑魔法,以及快捷方式的COM用法。 http://www.flexhex.com/docs/articles/hard-links.phtml

示例

执行下列脚本,生成链接。

@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

可以看到如下结果:

在这里插入图片描述

这里可以看到,在使用mklink时创建链接时,目标路径我都用了相对路径,但是可以看到软链接的目标路径已经计算成了绝对路径,而符号链接的目标路径还是之前写进去的相对路径,同样地,快捷方式和硬链接的目标路径也是绝对路径。

参考 https://ss64.com/nt/mklink.htmlhttps://en.wikipedia.org/wiki/NTFS_linkshttps://ss64.com/nt/shortcut.htmlhttps://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ishelllinkahttp://www.optimumx.com/downloads.html#Shortcuthttp://www.flexhex.com/docs/articles/hard-links.phtml


【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭