【发布时间】:2021-02-28 02:55:31
【问题描述】:
我需要对文件夹中的所有文件进行符号链接(不重复),只为符号链接添加扩展名,我可以使用精确的引用而不是通配符吗?
root@os:~/test# touch {a..z}
root@os:~/test# ls
a b c d e f g h i j k l m n o p q r s t u v w x y z
root@os:~/test# ln -s a a.txt
root@os:~/test# ls
a a.txt b c d e f g h i j k l m n o p q r s t u v w x y z
root@os:~/test# ln -s * *.txt
ln: target 'a.txt' is not a directory
【问题讨论】:
-
for i in *; do ln -s "$i" "$i.txt"; done -
因为
ln需要 2 个参数,而您传递了 27 个参数。想想*的含义。 -
输入
echo the command line with *.globbings以查看匹配的内容通常会有所帮助。 -
请注意,有关 UNIX 工具如何工作的问题属于 Unix & Linux,而不是这里 -- Stack Overflow 仅针对有关编写代码的问题。
-
@CharlesDuffy 我同意,但这是一个千钧一发的电话。如果将其放入脚本中,我想应该没问题。