create-symlink

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

创建软链接 (Create Symlink)

Create Symlink

指令

Instructions

当用户需要创建软链接时,首先检测操作系统类型,然后使用对应的命令:
When a user needs to create a symbolic link, first detect the operating system type, then use the corresponding command:

1. 检测操作系统

1. Detect Operating System

AI 通过以下方式判断当前系统:
  1. 查看环境变量中的系统信息:如
    process.platform
    (在 Node.js 环境中)
  2. 分析用户提供的路径格式
    • Windows 路径:
      C:\Users\...
      D:\...
    • macOS 路径:
      /Users/username/...
      ~/...
    • Linux 路径:
      /home/username/...
      ~/...
  3. 直接询问用户:当无法确定时,询问用户当前使用的操作系统
系统标识
  • Windows:
    win32
  • macOS:
    darwin
  • Linux:
    linux
AI determines the current system via the following methods:
  1. Check system information in environment variables: e.g.
    process.platform
    (in Node.js environment)
  2. Analyze the path format provided by the user:
    • Windows path:
      C:\\Users\\...
      or
      D:\\...
    • macOS path:
      /Users/username/...
      or
      ~/...
    • Linux path:
      /home/username/...
      or
      ~/...
  3. Ask the user directly: When it cannot be determined, ask the user which operating system they are currently using
System identifiers:
  • Windows:
    win32
  • macOS:
    darwin
  • Linux:
    linux

2. 创建目录软链接

2. Create Directory Symbolic Link

Windows (PowerShell):
powershell
New-Item -ItemType SymbolicLink -Path "目标路径" -Target "源路径"
Windows (CMD):
cmd
mklink /D "目标路径" "源路径"
macOS / Linux:
bash
ln -s "源路径" "目标路径"
Windows (PowerShell):
powershell
New-Item -ItemType SymbolicLink -Path "目标路径" -Target "源路径"
Windows (CMD):
cmd
mklink /D "目标路径" "源路径"
macOS / Linux:
bash
ln -s "源路径" "目标路径"

3. 创建文件软链接

3. Create File Symbolic Link

Windows (PowerShell):
powershell
New-Item -ItemType SymbolicLink -Path "目标文件路径" -Target "源文件路径"
Windows (CMD):
cmd
mklink "目标文件路径" "源文件路径"
macOS / Linux:
bash
ln -s "源文件路径" "目标文件路径"
Windows (PowerShell):
powershell
New-Item -ItemType SymbolicLink -Path "目标文件路径" -Target "源文件路径"
Windows (CMD):
cmd
mklink "目标文件路径" "源文件路径"
macOS / Linux:
bash
ln -s "源文件路径" "目标文件路径"

4. 创建硬链接(文件)

4. Create Hard Link (File)

Windows (CMD):
cmd
mklink /H "目标文件路径" "源文件路径"
macOS / Linux:
bash
ln "源文件路径" "目标文件路径"
Windows (CMD):
cmd
mklink /H "目标文件路径" "源文件路径"
macOS / Linux:
bash
ln "源文件路径" "目标文件路径"

使用场景

Usage Scenarios

使用此技能当用户:
  • 需要在不同位置共享同一个目录或文件
  • 想要创建快捷方式但保持原始路径引用
  • 需要跨目录访问文件而不想复制
  • 想要统一管理配置文件或资源
  • 在开发环境中链接依赖目录
  • 需要迁移大文件夹但保持原路径可用
Use this skill when the user:
  • Needs to share the same directory or file across different locations
  • Wants to create a shortcut while retaining the original path reference
  • Needs to access files across directories without copying
  • Wants to uniformly manage configuration files or resources
  • Links dependency directories in the development environment
  • Needs to migrate large folders while keeping the original path available

注意事项

Notes

权限要求

Permission Requirements

  • Windows: 创建软链接通常需要管理员权限(开发者模式可免除)
  • macOS / Linux: 普通用户可以创建软链接,但可能需要权限才能链接到某些系统目录
  • Windows: Creating symbolic links usually requires administrator privileges (can be exempted in Developer Mode)
  • macOS / Linux: Regular users can create symbolic links, but may require permissions to link to certain system directories

路径格式

Path Format

  • Windows: 使用完整路径,如
    C:\Users\name\folder
    "C:\Users\name\folder"
  • macOS / Linux: 使用完整路径,如
    /home/user/folder
    ~/folder
  • 避免使用相对路径,特别是在脚本中
  • Windows: Use full path, e.g.
    C:\\Users\\name\\folder
    or
    "C:\\Users\\name\\folder"
  • macOS / Linux: Use full path, e.g.
    /home/user/folder
    or
    ~/folder
  • Avoid using relative paths, especially in scripts

目标存在

Target Existence

  • 源路径必须存在才能创建软链接
  • 目标路径不能已存在(文件或目录)
  • The source path must exist to create a symbolic link
  • The target path must not already exist (file or directory)

跨文件系统

Cross Filesystem

  • 软链接可以跨文件系统创建
  • 硬链接不能跨文件系统创建
  • Symbolic links can be created across filesystems
  • Hard links cannot be created across filesystems

各平台示例

Examples for Each Platform

Windows 示例

Windows Example

创建目录软链接

Create Directory Symbolic Link

powershell
New-Item -ItemType SymbolicLink -Path "D:\shared\tools" -Target "C:\tools"
powershell
New-Item -ItemType SymbolicLink -Path "D:\\shared\\tools" -Target "C:\\tools"

创建文件软链接

Create File Symbolic Link

powershell
New-Item -ItemType SymbolicLink -Path "C:\Users\Public\Desktop\config.json" -Target "D:\MyConfigs\main-config.json"
powershell
New-Item -ItemType SymbolicLink -Path "C:\\Users\\Public\\Desktop\\config.json" -Target "D:\\MyConfigs\\main-config.json"

macOS 示例

macOS Example

创建目录软链接

Create Directory Symbolic Link

bash
ln -s /Users/username/Documents/work /Users/username/Desktop/work-link
bash
ln -s /Users/username/Documents/work /Users/username/Desktop/work-link

创建文件软链接

Create File Symbolic Link

bash
ln -s ~/.config/app/settings.json ~/Desktop/settings-link.json
bash
ln -s ~/.config/app/settings.json ~/Desktop/settings-link.json

Linux 示例

Linux Example

创建目录软链接

Create Directory Symbolic Link

bash
ln -s /home/user/projects/myapp /var/www/myapp
bash
ln -s /home/user/projects/myapp /var/www/myapp

创建文件软链接

Create File Symbolic Link

bash
ln -s /etc/nginx/sites-available/my-site /etc/nginx/sites-enabled/my-site
bash
ln -s /etc/nginx/sites-available/my-site /etc/nginx/sites-enabled/my-site

验证链接

Verify Links

Windows

Windows

powershell
undefined
powershell
undefined

查看链接详情

查看链接详情

Get-ChildItem "链接路径"
Get-ChildItem "链接路径"

查看是否为符号链接

查看是否为符号链接

(Get-Item "链接路径").Attributes
undefined
(Get-Item "链接路径").Attributes
undefined

macOS / Linux

macOS / Linux

bash
undefined
bash
undefined

查看链接详情

查看链接详情

ls -la "链接路径"
ls -la "链接路径"

验证链接指向

验证链接指向

readlink "链接路径"
readlink "链接路径"

查看链接和源文件

查看链接和源文件

ls -la "链接路径" "源路径"
undefined
ls -la "链接路径" "源路径"
undefined

删除软链接

Delete Symbolic Links

Windows

Windows

powershell
undefined
powershell
undefined

删除软链接(不要加 -Recurse,否则会删除源文件)

删除软链接(不要加 -Recurse,否则会删除源文件)

Remove-Item "链接路径"
undefined
Remove-Item "链接路径"
undefined

macOS / Linux

macOS / Linux

bash
undefined
bash
undefined

删除软链接(不要加 -r,否则会删除源文件)

删除软链接(不要加 -r,否则会删除源文件)

rm "链接路径"
rm "链接路径"

unlink "链接路径"
undefined
unlink "链接路径"
undefined

使用指南

Usage Guide

快速开始

Quick Start

查看 QUICK-REF.md 获取快速参考卡片
Check QUICK-REF.md for the quick reference card

详细指南

Detailed Guide

详细的使用说明请参考 USAGE.md 文件,其中包含了:
  • 各种触发关键词
  • 完整的对话示例
  • 常见使用场景
  • 注意事项提醒
For detailed usage instructions, please refer to the USAGE.md file, which includes:
  • Various trigger keywords
  • Complete conversation examples
  • Common usage scenarios
  • Notes and reminders