【问题标题】:command to search for files in a folder and move the files to different location命令搜索文件夹中的文件并将文件移动到不同的位置
【发布时间】:2017-11-24 08:45:30
【问题描述】:
I have a text file which has list of file names, I want to search these file names in a folder which has thousands of files and move the matching files to different location on linux.

有人可以帮助我执行此命令吗?

下面是我正在使用的代码

#!/bin/bash
file="/home/BILEKJ/Reprocess/data.txt"
while IFS= read -r line
do
    mv "/home/BILEKJ/Reprocess/EDI855/$line" "/home/BILEKJ/Reprocess/Final855" >/dev/null 2>&1
done <"$file"

【问题讨论】:

  • 文件名列表有多“大”?
  • 该列表有大约 4000 个文件名

标签: grep find cp mv


【解决方案1】:

试试这样的:

file="data.txt"
while IFS= read -r line
do
        mv "/your/path/$line"  "/dest/path" >/dev/null 2>&1
done <"$file"

【讨论】:

  • 这个不行,上面的命令中read怎么知道从哪个文件读取数据
  • @user2231076 .....参见代码块中的第一行,"data.txt" 只是一个示例。
  • 是的,我使用我的输入文件名作为 data.txt 并没有工作
  • @user2231076 “不起作用”不是一个好的描述,请从您的文件中显示几行。
  • #!/bin/bash while IFS='' read -r line do mv "/cygdrive/c/cygwin64/home/BILEKJ/Reprocess/EDI855/$line" "/cygdrive/c/ cygwin64/home/BILEKJ/Reprocess/Final855" >/dev/null 2>&1 done 我正在运行脚本./NewMove.sh data.txt
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-18
  • 2019-07-11
  • 2022-12-25
  • 1970-01-01
  • 2020-01-13
  • 1970-01-01
相关资源
最近更新 更多