如何使用字符串替换重命名linux中的目录中的所有文件?

时间:2016-07-30 10:13:40

标签: linux bash slackware

我想重命名我的linux系统目录中的多个文件....

我的文件名是:

Lec 1 - xxx.webm
Lec 2 - xxx.webm
Lec 3 - xxx.webm
Lec 4 - xxx.webm

并且列表继续......

这里xxx可以是任何字符列表(不一致)....

我想重命名这里的每个文件,如:

mv Lec 1 - xxx.webm Lec 1.webm
mv Lec 2 - xxx.webm Lec 2.webm
mv Lec 3 - xxx.webm Lec 3.webm

依旧......

对于in循环,

可以做但是如何进行替换?

*删除所有字符后的数字应该是我的重命名文件

3 个答案:

答案 0 :(得分:2)

这个for循环应该完成这项工作:

public class A
{
    //Property
    //must be set somewhere (e.g. constructor)
    public List<Product> Products { get; private set; }

    //Method
    public List<Product> GetProducts()
    {
        //return list of products
    }
}

public class B
{
    public void Display()
    {
        var a = new A(); 
        foreach (var product in a.Products /*OR a.GetProducts()*/)
        {
            Console.WriteLine(product);
        }
    }

}

答案 1 :(得分:1)

$(document).on('submit', 'form[data-pjax]', function(event) { $.pjax.submit(event, '#pjax-container') }) :从${string%substring}后面删除$substring的最短匹配。

$string

或退房:

for i in *.webm; do mv $i ${i%xxx}; done :从${string%%substring}后面删除$substring的最长匹配。

答案 2 :(得分:0)

如果您安装了util-linux-ng

find . -name "Lec*.webm" | xargs rename s/ -*//

或:

for file in $(find . -name "Lec*.webm")
do 
  echo mv $file `echo $file | sed s/ -*$//`
done