About create-symlink
A skill that guides users through creating symbolic links and file hard links. It determines the appropriate command from the operating system and path format, and includes verification and removal guidance.
Key features
- 01Identify operating system and path format
- 02Create file and directory symbolic links
- 03Create file hard links
- 04Verify link targets
- 05Remove links without deleting source
Use cases
- 01Share files or directories without copying
- 02Link configuration files across locations
- 03Link dependency directories in development
- 04Keep an original path available after moving a large folder
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ steelan9199/ wechat-publisher --skill create-symlinkAfter installing, type/create-symlinkin Claude Code to confirm it loaded.
Bundled filesQUICK-REF.mdUSAGE.md
Details
From the project README创建软链接 (Create Symlink)
指令
当用户需要创建软链接时,首先检测操作系统类型,然后使用对应的命令:
1. 检测操作系统
AI 通过以下方式判断当前系统:
- 查看环境变量中的系统信息:如
process.platform(在 Node.js 环境中) - 分析用户提供的路径格式:
- Windows 路径:
C:\Users\...或D:\... - macOS 路径:
/Users/username/...或~/... - Linux 路径:
/home/username/...或~/...
- Windows 路径:
- 直接询问用户:当无法确定时,询问用户当前使用的操作系统
系统标识:
- Windows:
win32 - macOS:
darwin - Linux:
linux
2. 创建目录软链接
Windows (PowerShell):
New-Item -ItemType SymbolicLink -Path "目标路径" -Target "源路径"
Windows (CMD):
mklink /D "目标路径" "源路径"
macOS / Linux:
ln -s "源路径" "目标路径"
3. 创建文件软链接
Windows (PowerShell):
New-Item -ItemType SymbolicLink -Path "目标文件路径" -Target "源文件路径"
Windows (CMD):
mklink "目标文件路径" "源文件路径"
macOS / Linux:
ln -s "源文件路径" "目标文件路径"
4. 创建硬链接(文件)
Windows (CMD):
mklink /H "目标文件路径" "源文件路径"
macOS / Linux:
ln "源文件路径" "目标文件路径"
使用场景
使用此技能当用户:
- 需要在不同位置共享同一个目录或文件
- 想要创建快捷方式但保持原始路径引用
- 需要跨目录访问文件而不想复制
- 想要统一管理配置文件或资源
- 在开发环境中链接依赖目录
- 需要迁移大文件夹但保持原路径可用
注意事项
权限要求
- Windows: 创建软链接通常需要管理员权限(开发者模式可免除)
- macOS / Linux: 普通用户可以创建软链接,但可能需要权限才能链接到某些系统目录
路径格式
- Windows: 使用完整路径,如
C:\Users\name\folder或"C:\Users\name\folder" - macOS / Linux: 使用完整路径,如
/home/user/folder或~/folder - 避免使用相对路径,特别是在脚本中
目标存在
- 源路径必须存在才能创建软链接
- 目标路径不能已存在(文件或目录)
跨文件系统
- 软链接可以跨文件系统创建
- 硬链接不能跨文件系统创建
各平台示例
Windows 示例
创建目录软链接
New-Item -ItemType SymbolicLink -Path "D:\shared\tools" -Target "C:\tools"
创建文件软链接
New-Item -ItemType SymbolicLink -Path "C:\Users\Public\Desktop\config.json" -Target "D:\MyConfigs\main-config.json"
macOS 示例
创建目录软链接
ln -s /Users/username/Documents/work /Users/username/Desktop/work-link
创建文件软链接
ln -s ~/.config/app/settings.json ~/Desktop/settings-link.json
Linux 示例
创建目录软链接
ln -s /home/user/projects/myapp /var/www/myapp
创建文件软链接
ln -s /etc/nginx/sites-available/my-site /etc/nginx/sites-enabled/my-site
验证链接
Windows
# 查看链接详情
Get-ChildItem "链接路径"
# 查看是否为符号链接
(Get-Item "链接路径").Attributes
macOS / Linux
# 查看链接详情
ls -la "链接路径"
# 验证链接指向
readlink "链接路径"
# 查看链接和源文件
ls -la "链接路径" "源路径"
删除软链接
Windows
# 删除软链接(不要加 -Recurse,否则会删除源文件)
Remove-Item "链接路径"
macOS / Linux
# 删除软链接(不要加 -r,否则会删除源文件)
rm "链接路径"
# 或
unlink "链接路径"
使用指南
快速开始
查看 QUICK-REF.md 获取快速参考卡片
详细指南
详细的使用说明请参考 USAGE.md 文件,其中包含了:
- 各种触发关键词
- 完整的对话示例
- 常见使用场景
- 注意事项提醒
Comments
Markdown supported