[英]Shell script copy file from one dir to another
I am trying to copy a file from a dir to another directory location using regx * like below我正在尝试使用 regx * 将文件从目录复制到另一个目录位置,如下所示
cp /location1/abc_* /location/xyz_
Its failing to copy because In location1 there are many files with abc_123 abc_234 like these.它无法复制,因为在 location1 中有很多带有 abc_123 abc_234 这样的文件。
Seems like command get confuse to copy which file as xyz_似乎命令混淆了将哪个文件复制为 xyz_
I want to copy only the file which is recent abc_ file.我只想复制最近的 abc_ 文件。 Is there any way to achieve this requirement?
有没有办法达到这个要求?
You can iterate over the glob to select the most recent file, then copy that one file.您可以遍历全局到 select 最新文件,然后复制该文件。 (Every file compares as "newer" than a non-existent file
(每个文件都比不存在的文件“更新”
newest=
for f in /location1/abc_*; do
[[ $f -nt $newest ]] && newest=$f
done
cp "$newest" /location/xyz_/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.