shell 从文件列表创建符号链接

np8igboo  于 2023-08-07  发布在  Shell
关注(0)|答案(2)|浏览(106)

我有一个文件夹,其中包含多个文件和一个文件(file_list),其中列出了感兴趣的文件。我想创建符号链接,指向与列表中的文件名匹配的所有文件。在bash中有简单的方法吗?
范例:

  • 文件夹包含:file1file2file3file4file5
  • file_list的内容:file1, file3, file5
  • 目标文件夹应包含:file1file3file5的符号链接
zvokhttg

zvokhttg1#

类似这样的东西应该做:

#!/usr/bin/env bash 

while IFS= read -r file; do
    [[ -e /some/path/$file ]] && ln -s "/some/path/$file" /dest/path
done < file_list

字符串

bejyjqdl

bejyjqdl2#

像这样的东西应该像cp -s制作符号链接一样工作

cp -s $(cat file_list) /path/to/destination/dir/

字符串

相关问题