[英]Shell script - Find files modified today, create directory, and move them there
[英]Create Unix shell script to move non empty files from Source directory to Target directory and add timestamp to them
我正在尝试创建一个 shell 脚本以将非空文件从源目录移动到目标目录并为它们添加时间戳。 我在用
find . -type f -size +0 -print0 | xargs -I {} -r0 mv {} $Tgt_dir/{}_`date +%m%d%Y`
但它不工作。 能否请你帮忙。
谢谢
您可以在find
使用-printf
来打印mv
命令,其中包含源的完整路径和目标中的基本名称,并将其通过管道传输到 shell:
date=$(date +%m%d%Y)
find . -type f -size +0 -printf "mv '%p' '$Tgt_dir/%f_$date'" | bash
%p
是完整路径名, %f
是基本名称。
要移动至少一行的文件,请编写一个计算行数的命令:
date=$(date +%m%d%Y)
find "$Src_dir" -type f -size +0 -printf "if [ $(wc -l '$p') -gt 1 ]; then mv '%p' '$Tgt_dir/%f_$date'; fi" | bash
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.