我正在尝试将一些文件从/path/to/folder1
符号链接到/path/to/folder2
,并将一些自定义文本附加到生成的符号链接名称中,但是,在最终确定正确处理basename之后,语法要么不起作用或我cd
/path/to/folder2
只使用${file%%.*}-something.txt
文件符号链接到/path/to/folder1
。
这是我的代码:
for file in $(find /path/to/folder1 -iname '*.txt' ! -name 'file.txt' -type f)
do ln -s $file /path/to/folder2/${file%%.*}-something.txt
done
如何正确地做到这一点?
答案 0 :(得分:2)
对于文件/path/to/folder1/abc.txt
,${file%%.*}
会为您提供/path/to/folder1/abc
所以你ln
命令转换为:
ln -s /path/to/folder1/abc.txt /path/to/folder2//path/to/folder1/abc-something.txt
如果您想将/path/to/folder1/abc.txt
与/path/to/folder2/abc-something.txt
相关联,可以这样做:
for file in $(find /path/to/folder1 -iname '*.txt' ! -name 'file.txt' -type f)
do ln -s $file /path/to/folder2/$(basename $file .txt)-something.txt
done