“批量建软连接(符号链接)”通常分两种场景:把一批源文件/目录分别链接到目标目录,或按列表批量生成。下面按常见系统和方式给你最实用的做法。
ln -s /source_dir/* /target_dir/
⚠️ 注意:
* 不包含隐藏文件(.xxx)cp -rs /source_dir/* /target_dir/
-r 递归-s 创建软链接find /source_dir -type f -exec ln -s {} /target_dir/ \;
只链文件:
find /source_dir -type f
只链目录:
find /source_dir -type d
假设有 list.txt:
/a/1.txt
/a/2.txt
while read f; do
ln -s "$f" /target_dir/
done < list.txt
for %f in (C:\src\*) do mklink "D:\dst\%~nxf" "%f"
Get-ChildItem C:\src | ForEach-Object {
New-Item -ItemType SymbolicLink -Path "D:\dst\$($_.Name)" -Target $_.FullName
}
-f 强制覆盖(Linux)如果你能告诉我:
我可以给你直接可复制的精准命令。