使用 shell 批量 复制文件 到 目标目录中

使用 shell 批量 复制文件 到 目标目录中

#! /bin/bash

path=$1 #源目录
topath=$2 #目标目录

find ${path} -name "*" -type f -size 0c | xargs -n 1 rm -f

if [ ! -d "$topath" ]
then
mkdir -p "$topath"
fi

while(true)
do
for file in ls $path
do
yes|cp ${path}/${file} ${topath}/${file}
sleep 3s
done

sleep 3s

done

====================================================================

每3秒复制一个文件到目标目录

启动

shell 源目录 目标目录

find ${path} -name "*" -type f -size 0c | xargs -n 1 rm -f
使用find 查询源目录中 文件大小为空的文件 并删除
if [ ! -d "$topath" ]
then
mkdir -p "$topath"
fi
判断目标目录是否存在,不存在则创建

yes|cp ${path}/${file} ${topath}/${file}

强制复制 源目录中的文件到目标目录中

猜你喜欢

转载自blog.51cto.com/15084467/2621334
今日推荐