link 个目录中的文件,使用类似于 cp 的简单命令
link files within directory, with simple command similar to cp
我的问题来源:
- 当 运行 宁
cp source/files.all destination/
时,source
中的所有文件现在也将存在于 destination
中
问题:
如果我不想将数据从 source
复制到 destination
,而只是 link 它们( 和绝对路径)。通常,我会 运行 像这样:
for f in $(ls source/); do ln -s $(pwd)/${f} $(pwd)/destination; done
有没有我可以使用的简单 command/tool(例如 ln -a source/files.all destination/
),它将为目录中的所有文件创建软 link,而 自动添加绝对路径 作为前缀。 ln -r
接近我需要的,但是是绝对路径,不是相对路径?
我会使用 find "$PWD/source" -exec ln -s {} destination \;
。用作 find
的第一个参数的绝对路径将导致 {}
被替换为每个命令的源文件的绝对路径。
GNU ln
支持 -t
选项来指定目标目录,允许您更有效地调用 find
:
find "$PWD/source" -exec ln -s -t destination {} +
-exec ... +
形式要求{}
是命令中的最后一个参数; -t
允许您向上移动目标参数以满足该要求。
所以我最终找到了一种简单的方法来做到这一点:
简直运行ln -s $(pwd -P)/source/* destination/
我的问题来源:
- 当 运行 宁
cp source/files.all destination/
时,source
中的所有文件现在也将存在于destination
中
问题:
如果我不想将数据从
source
复制到destination
,而只是 link 它们( 和绝对路径)。通常,我会 运行 像这样:for f in $(ls source/); do ln -s $(pwd)/${f} $(pwd)/destination; done
有没有我可以使用的简单 command/tool(例如
ln -a source/files.all destination/
),它将为目录中的所有文件创建软 link,而 自动添加绝对路径 作为前缀。ln -r
接近我需要的,但是是绝对路径,不是相对路径?
我会使用 find "$PWD/source" -exec ln -s {} destination \;
。用作 find
的第一个参数的绝对路径将导致 {}
被替换为每个命令的源文件的绝对路径。
GNU ln
支持 -t
选项来指定目标目录,允许您更有效地调用 find
:
find "$PWD/source" -exec ln -s -t destination {} +
-exec ... +
形式要求{}
是命令中的最后一个参数; -t
允许您向上移动目标参数以满足该要求。
所以我最终找到了一种简单的方法来做到这一点:
简直运行ln -s $(pwd -P)/source/* destination/