gpt4 book ai didi

Linux bash 文件 : RENAME subdirs by count of files in them

转载 作者:太空宇宙 更新时间:2023-11-04 05:30:32 24 4
gpt4 key购买 nike

**1。我想编写 LINUX bash 文件,并且想重命名子目录/文件夹 其中的文件数量(以及子文件夹中的文件数量,如果存在)示例:我有这样的结构(我有大约 300 个文件夹,并且子文件夹的随机数量包含文件)

MUSIC
-CD1
--ELTON
--MADONA
-CD34
--SUMER
-CDBESTOF2013
--WINTER
--2009
--2010
-CDGREATTESTHITS
--HITS1
--HITS30

<强>......

CD1 had 35 *.mp3 files in ALL SUBFOLDERS
CD34 had 10 *.mp3 files in ALL SUBFOLDERS
CDBESTOF2013 had 300 *.mp3 files in ALL SUBFOLDERS
CDGREATTESTHITS had 99 *.mp3 files in ALL SUBFOLDERS

I want to run Linux bash file to rename/add sufix to subdirs by
count of files in them RESULT:

MUSIC
-CD1_35
-CD34_10
-CDBESTOF2013_300
-CDGREATTESTHITS_99

<强>......谢谢...**

最佳答案

给你。

for dirs in music/*; do
count=$(find "$dirs" -type f | wc -l)
mv "$dirs" "${dirs}_${count}"
done

for 循环 将列出 music/ 中的所有子目录,并将每个目录名称分配给 $dirs

count 将获取子目录中的文件数量。

关于Linux bash 文件 : RENAME subdirs by count of files in them,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20818457/

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