【问题标题】:Remove part of filename for multiple files using bash使用 bash 删除多个文件的部分文件名
【发布时间】:2022-11-17 03:12:39
【问题描述】:

我有多个文件名为 01 - a.txt02 - b.txt03 - c.txt 等。我想删除初始编号和破折号,以将所有文件命名为a.txtb.txtc.txt。我不擅长 bash,所以我会非常感谢一些帮助。

非常感谢!

【问题讨论】:

  • 这已经是answered
  • 不完全是,因为我相信这需要一个 for 循环和整数到字符串的转换。
  • rename -n 's/.* //' *.txt

标签: bash sh


【解决方案1】:

使用substring removal##*-

例如。

$ arr=("01 - a.txt" "02 - b.txt" "03 - c.txt")

$ echo "${arr[@]##*- }"
a.txt b.txt c.txt

在一个循环中

for i in *-*.txt;do echo "$i" "${i##*- }";done
01 - a.txt a.txt
02 - b.txt b.txt
03 - c.txt c.txt

如果输出看起来正常,请将 echo 替换为 mv

【讨论】:

    猜你喜欢
    • 2014-03-08
    • 1970-01-01
    • 2012-08-23
    • 1970-01-01
    • 2023-04-01
    • 2017-04-08
    • 2017-01-13
    • 2020-02-15
    • 2017-12-23
    相关资源
    最近更新 更多