重命名多个文件外壳 [英] Rename multiple files shell
问题描述
我在一个目录多个文件,例如: linux_file1.mp4
, linux_file2.mp4
等。如何移动这些文件,使用的外壳,使名称 file1.mp4
, file2.mp4
等上。我有大约30个文件,我想移动到新的名称。
I have multiple files in a directory, example: linux_file1.mp4
, linux_file2.mp4
and so on. How do I move these files, using shell, so that the names are file1.mp4
, file2.mp4
and so on. I have about 30 files that I want to move to the new name.
推荐答案
我喜欢 MMV 一>为这种事情
mmv 'linux_*' '#1'
但你也可以使用改名
。要知道,有常用的两个改名
具有非常不同的语法命令。一种是用Perl编写的,另一种是分布有UTIL Linux的,所以我分辨他们是重命名的perl和重命名UTIL的。
But you can also use rename
. Be aware that there are commonly two rename
commands with very different syntax. One is written in Perl, the other is distributed with util-linux, so I distinguish them as "perl rename" and "util rename" below.
使用Perl的重命名:
With Perl rename:
rename 's/^linux_//' linux_*.mp4
由于cweiske正确地指出。
As cweiske correctly pointed out.
通过UTIL重命名:
rename linux_ '' linux_*.mp4
你怎么知道哪个重命名你有吗?尝试运行重命名-V
;如果你的版本UTIL将其重命名将打印版本号,如果是perl的重命名,将无害报告和未知的选项,并显示使用。
How can you tell which rename you have? Try running rename -V
; if your version is util rename it will print the version number and if it is perl rename it will harmlessly report and unknown option and show usage.
如果你没有任何改名
或 MMV
并不愿或无法安装他们仍然可以用普通老贝code实现这一点:
If you don't have either rename
or mmv
and don't want to or can't install them you can still accomplish this with plain old shell code:
for file in linux_*.mp4 ; do mv "$file" "${file#linux_}" ; done
此语法将与任何POSIX SH符合XPG4或更高版本,这是基本上所有的炮弹,这些天的工作。
This syntax will work with any POSIX sh conforming to XPG4 or later, which is essentially all shells these days.
这篇关于重命名多个文件外壳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!