如何在单个目录中以最少的分叉数量创建符号链接?
在以下情况下如何在单个目录中创建符号链接:
- 常见方法失败:
ln -s /readonlyShare/mydataset/*.mrc .
# -bash: /bin/ln: Argument list too long
find
命令不允许使用以下语法:
find /readonlyShare/mydataset -maxdepth 1 -name '*.mrc' -exec ln -s {} . +
# find: missing argument to `-exec'
- 使用狂野分叉需要数小时才能完成:
find /readonlyShare/mydataset -maxdepth 1 -name '*.mrc' -exec ln -s {} . ';'
How to create symlinks in a single directory when:
- The common way fails:
ln -s /readonlyShare/mydataset/*.mrc .
# -bash: /bin/ln: Argument list too long
- The
find
command doesn't allow the following syntax:
find /readonlyShare/mydataset -maxdepth 1 -name '*.mrc' -exec ln -s {} . +
# find: missing argument to `-exec'
- Using wild forking takes hours to complete:
find /readonlyShare/mydataset -maxdepth 1 -name '*.mrc' -exec ln -s {} . ';'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
或者如果您更喜欢
xargs
:如果您使用的是 BSD
xargs
而不是 GNUxargs
,那么它会更简单:为什么
'{} ''+'
?引自
man find
:find
擅长分割大量参数:为什么不使用
xargs -I
?它效率不高而且速度慢,因为
-I
按每个参数执行实用程序,例如:xargs
也擅长分割大量参数为什么
sh -c< /代码>?
只有 BSD
xargs
有-J
标志来将参数放在命令中间。对于 GNUxargs
,我们需要结合sh -c
和"$@"
来完成同样的事情。find -exec
与find | xargs
这取决于情况,但我建议当您想利用所有 CPU 时使用
xargs
。xargs
可以通过-P
并行执行实用程序,而find
则不能。or if you prefer
xargs
:If you are using BSD
xargs
instead of GNUxargs
, it can be simpler:Why
'{}' '+'
?Quoted from
man find
:find
is good at splitting large number of arguments:Why not
xargs -I
?It is not efficient and slow because
-I
executes the utility per argument, for example:xargs
is also good at splitting large number of argumentsWhy
sh -c
?Only BSD
xargs
have-J
flag to put arguments in the middle of commands. For GNUxargs
, we need the combination ofsh -c
and"$@"
to do the same thing.find -exec
vsfind | xargs
It depends but I would suggest use
xargs
when you want to utilize all your CPUs.xargs
can execute utility parallelly by-P
whilefind
can't.当我需要它的时候,我很着急,所以我没有探索所有的可能性,但我同时解决了一些问题
感谢@WeihangJian的回答,我现在知道
找到... | xargs -I {} ...
与find ... -exec ... {} ';'
一样糟糕。我的问题的正确答案是:
I was in a rush when I needed it so I didn't explore all possibilities but I worked-out something meanwhile
Thanks to @WeihangJian answer I now know that
find ... | xargs -I {} ...
is as bad asfind ... -exec ... {} ';'
.A correct answer to my question would be: