Centos8中如何更改文件夹中多个文件的扩展名

本教程将讨论将文件从特定扩展名更改为另一个扩展名的快速方法。我们将为此使用 shell循环、rename命令

方法一:使用循环

在目录中递归更改文件扩展名的最常见方法是使用 shell 的 for 循环。我们可以使用 shell 脚本提示用户输入目标目录、旧的扩展名和新的扩展名以进行重命名。以下是脚本内容:

[root@localhost ~]# vim rename_file.sh
#!/bin/bash
echo "Enter the target directory "
read target_dir
cd $target_dir
 
echo "Enter the file extension to search without a dot"
read old_ext
 
echo "Enter the new file extension to rename to without a dot"
read new_ext
 
echo "$target_dir, $old_ext, $new_ext"
 
for file in *.$old_ext
do
    mv -v "$file" "${file%.$old_ext}.$new_ext"
done;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值