在bash重命名文件 [英] Renaming files in bash

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

问题描述

我的目录下有命名为20130101_temp.txt,20130102_temp.txt等。

My directory has many files named as "20130101_temp.txt", "20130102_temp.txt", etc.

我如何删除所有这些文件的名称_temp。即,重命名为20130101_temp.txt 20130101.txt。

How do I remove the "_temp" in the names of all these files. i.e., rename 20130101_temp.txt to 20130101.txt.

推荐答案

使用bash:

for x in *_temp.txt
do
    mv $x ${x%%_temp.txt}.txt
done

还有随叫Perl的(至少在Ubuntu)的多用途改名,接受一个正前pression,所以你可以完成的同样的事情

There's also a utility that comes with Perl (at least on Ubuntu) called rename which takes a regular expression, so you could accomplish the same thing with:

rename -n 's/_temp\.txt$/.txt/' *_temp.txt

-n 选项启动试运行,将只显示你是怎么回事改名。删除其实际执行的重命名。

The -n option initiates a "dry run" that will only show you what is going to be renamed. Remove it to actually perform the rename.

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

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