gpt4 book ai didi

linux - 在 Linux 上展平目录结构时将数字附加到文件名

转载 作者:太空狗 更新时间:2023-10-29 12:38:34 25 4
gpt4 key购买 nike

我的目录结构如下所示:

/a/f.xml
/b/f.xml
/c/f.xml
/d/f.xml

我想做的是将所有 xml 文件复制到一个目录中,如下所示:

/e/f_0.xml
/e/f_1.xml
/e/f_2.xml
/e/f_3.xml

我怎样才能在 Linux shell 上高效地做到这一点?

最佳答案

let count=0
for file in $(ls $dir)
do
mv $file $newdir/${file%%.*}_$count.${file##*.}
let count=count+1
done

关于linux - 在 Linux 上展平目录结构时将数字附加到文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2336384/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com