简体   繁体   English

如何读取包含字符串的文件并在目录中找到它

[英]How to read file containing a string and finding it in a directory

I have a file with a list of file names. 我有一个带有文件名列表的文件。 I want to find each of those files and copy it to some directory, is this possible in linux? 我想找到每个文件并将其复制到某个目录,这在Linux中可能吗?

ListOfFileNames.txt
xyz.txt
ags.txt
shd.txt
...

Directory_to_be searched
dsf.txt
xyz.txt
shd.txt
...

Empty_new_directory

So copy xyz.txt, ags.txt, shd.txt and place them in Empty_new_directory 因此,复制xyz.txt,ags.txt,shd.txt并将它们放在Empty_new_directory中

Any help will be appreciated 任何帮助将不胜感激

xargs cp -t /app/dest/ < ListOfFileNames.txt xargs cp -t / app / dest / <ListOfFileNames.txt

Does not work? 不行吗?

Maybe use of find command 也许使用find命令

If there's no nesting, then you can use a simple loop with cp : 如果没有嵌套,则可以对cp使用一个简单的循环:

SOURCE='Directory_to_be_searched'
TARGET='Empty_new_directory'

cat File.txt |  while read filename; do
    cp "${SOURCE}/${filename}" "${TARGET}/${filename}"  
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将包含目录作为前缀添加到复制的文件名? - How could I add the containing directory as a prefix to a copied file name? Bash:如何在包含多个条件的while循环中读取文件? - Bash: How to read file in while loop containing multiple conditions? 为每个目录寻找最大的文件 - finding largest file for each directory 如何在 Linux 文件中用包含另一行(新目录路径)的变量替换一行(目录路径)? - How to replace a line (directory path) with a variable containing another line (new directory path) in a Linux file? 读取未知目录中的文件 - Read file in unknown directory 使用 grep 计算目录中包含字符串的所有行 - Count all lines containing a string in a directory with grep 如何在包含文本文件中带有模式的字符串的行的末尾添加文本? - How to add text at the end of a line containing a string with a pattern in a text file? 如何使用sed命令从文件中删除包含特定字符串的行 - How to remove a line containing specific string from file with sed command 如何用包含换行符的字符串替换文件的内容? - How to replace a file's content with a string containing new line characters? 如何循环浏览目录中的文件,然后将它们读入bash中的字符串变量 - How to loop through files in a directory and then read them into a string variable in bash
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM