当前位置:网站首页>重命名文件夹下的所有子文件夹名,重命名子文件夹下的所有子文件夹名
重命名文件夹下的所有子文件夹名,重命名子文件夹下的所有子文件夹名
2022-08-07 14:44:00 【WangLanguager】
1、想要重命名文件夹下的所有子文件夹的名称,所有的子文件夹的名称都加上文件夹的名称前缀
代码如下:
#!/bin/bash
mkdir ../newtest
ls -1 > ../newtest/dirName.txt
bName=$(basename `pwd`)
for name in $(cat ../newtest/dirName.txt)
do
#echo $bName
#echo $name
newName=$bName$name
#echo $newName
mv $name $newName
done
$(cp -rf ./$name ../newtest)代码解释如下:
#!/bin/bash
mkdir ../newtest //创建一个新的测试目录
ls -1 > ../newtest/dirName.txt //将当前目录下的所有文件夹名列出,并保存在dirName.txt文件内
bName=$(basename `pwd`) //获取当前目录的名称
for name in $(cat ../newtest/dirName.txt) //遍历所有的子文件名
do
#echo $bName
#echo $name
newName=$bName$name //将子文件夹名加上“当前目录名称”的前缀
#echo $newName
mv $name $newName //将子文件夹名进行更改
done
$(cp -rf ./$name ../newtest) //将改名后的子文件夹拷贝到newtest目录下
2、想要重命名子文件夹下的所有子文件夹名称,所有的子文件夹的子文件夹名称都加上子文件夹的名称前缀
代码如下:
#!/bin/bash
mkdir ../newtest
ls -1 > ../newtest/dirName.txt
for name in $(cat ../newtest/dirName.txt)
do
cd $name
ls -1 > ../../newtest/subdirName.txt
subName=$(basename `pwd`)
echo $subName
for subname in $(cat ../../newtest/subdirName.txt)
do
echo $subname
newsubName=$subName$subname
echo $newsubName
mv -f $subname $newsubName
cp -rf ./$newsubName ../../newtest
done
cd ../
done代码解释如下:
#!/bin/bash
mkdir ../newtest //创建一个新的测试目录
ls -1 > ../newtest/dirName.txt //将当前目录下的所有文件夹名列出,并保存在dirName.txt文件内
for name in $(cat ../newtest/dirName.txt) //遍历所有的子文件名
do
cd $name //进入子文件
ls -1 > ../../newtest/subdirName.txt //将当前目录下的所有文件夹名列出,并保存在subdirName.txt文件内
subName=$(basename `pwd`) //获取子文件夹的名称
echo $subName
for subname in $(cat ../../newtest/subdirName.txt) //遍历当前子文件夹的所有的子文件名
do
echo $subname
newsubName=$subName$subname //将子文件夹名加上“当前目录名称”的前缀
echo $newsubName
mv -f $subname $newsubName //将子文件夹名进行更改
cp -rf ./$newsubName ../../newtest //将改名后的子文件夹拷贝到newtest目录下
done
cd ../
done
边栏推荐
- MethodInterceptor
- Acwing/3359. 更多奇怪的照片
- LeetCode 热题 HOT 100(1.两数之和)
- 【HCIP】BGP 选路问题小型实验
- Summary of the open surface
- Lianshengde W801 series 1-flash save data routine: save wifi distribution network information
- Lianshengde W801 series 2-WIFI one-key distribution network, information preservation
- 浏览器工作原理与实践学习笔记(一)宏观视角下的浏览器
- Niu Ke Interview High Frequency List (Group 2) Difficulty: Easy & Moderate
- Is it safe to use a straight flush in stocks?Will the funds be transferred?
猜你喜欢

手工测试转自动化,学习路线必不可少,更有【117页】测开面试题,欢迎来预测

Threads of control and synchronization

嵌入式开发:嵌入式基础–了解微控制器引导过程
![[Add and delete vscode code snippets]](/img/8a/2a959184c715aee7a59bc4cb409722.png)
[Add and delete vscode code snippets]
![[HCIP] Small Experiment on BGP Routing Problem](/img/a2/68221545ad7bf2df7ca6edabacc27d.png)
[HCIP] Small Experiment on BGP Routing Problem

锁相环工作原理

C Expert Programming Chapter 7 Thinking About Memory 7.8 Take it easy --- "Thing King" and "Page Game"
![[YOLOv7_0.1] Network structure and source code analysis](/img/62/1c47bd236f6acaf4bad94880970093.png)
[YOLOv7_0.1] Network structure and source code analysis

Solidigm officially launches PCIe 4.0 solid state drive Solidigm P41 Plus

GCB | 华中农大刘玉荣组在海拔梯度下土壤碳周转领域取得系列新进展
随机推荐
004_Eureka注册中心
锁相环工作原理
【PTA】L2-033 Simple Calculator (25 points)
Domain objects share data
【PTA】L2-002 Deduplication of linked list (25 points)
win10 uwp iot
HJ3 obvious random number
【Electrical Engineering (Part 2)】Organization of some basic concepts
Expert C Programming Chapter 8 Why Programmers Can't Tell the Difference Between Halloween and Christmas 8.3 Types Change While Waiting
[Add and delete vscode code snippets]
dotnet 获取当前进程方法
[YOLOv5] Combined with GradCAM heat map visualization
【PTA】L2-002 链表去重(25分)
C专家编程 第8章 为什么程序员无法分清万圣节和圣诞节 8.2 根据位模式构筑图形
Solidigm officially launches PCIe 4.0 solid state drive Solidigm P41 Plus
How about Qiniu's CITIC Securities VIP commission account?Is it safe and reliable?
自动化测试、测试左移、精准测试,一次性说透
一天学会从抓包到接口测试,通过智慧物业项目深度解析
LeetCode Hot Questions HOT 100 (1. Sum of two numbers)
Codeforces Round #812 (Div. 2)