首页 > 解决方案 > 将带有路径的文件名与文件一起移动到目录中的文件

问题描述

我只移动正在使用的文本文件中的文件名:

cd /data/sources/
find $PWD -type f -name "Asset_*">> /data/processing/asset_files.txt

但是,我还需要:

  1. 也将Asset_*文件移动到/data/processing/.
  2. 将前 1000 个文件移动到/data/processing/.

我如何添加这两个东西?

标签: bashshellunix

解决方案


重构@Dominique 的答案,您可以使用 find 命令并移动文件。这可能需要很多时间(取决于文件数量),命令如下:

cd /data/sources/
find $PWD -type f -name "Asset_*" -exec mv {} /target_dir \;

如果您想准确移动 1000 个文件,您可以使用类似

a=1
cd /data/sources/
for i in $PWD/Asset_*
do
mv "$i" /target_dir
a=$(($a + 1))
if [ "$a" -gt 1000 ]
then break
fi
done

推荐阅读