如何在bash中使用通配符重命名文件? [英] How to rename files using wildcard in bash?

查看:41
本文介绍了如何在bash中使用通配符重命名文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将某些文件重命名为另一个扩展名:

I was trying to rename some files to another extension:

# mv  *.sqlite3_done *.sqlite3

但出现错误:

mv: target '*.sqlite3' is not a directory

为什么?

推荐答案

通配符扩展导致将多个名称传递给命令.Shell认为您正在尝试将多个文件移动到 *.sqlite3 目录.

The wildcard expansion results in multiple names being passed to the command. The shell thinks you are trying to move multiple files to the *.sqlite3 directory.

您需要使用循环:

for nam in *sqlite3_done
do
    newname=${nam%_done}
    mv $nam $newname
done

%_ done 说要从字符串中删除最后一次出现的 _done .

The %_done says to remove the last occurrence of _done from the string.

如果文件名中可能包含空格,则需要引用文件名.

If you may have spaces in your filenames you will want to quote the filenames.

这篇关于如何在bash中使用通配符重命名文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆