找到所有 [filename].mp4 并重命名 [filename].audio

Fre*_*ers 2 find rename files

所以我有一个脚本,它使用$1.audio文件中的音频将 2 部电影添加到一起。我想做的是重命名目录中的任何文件:

*.mp4 
Run Code Online (Sandbox Code Playgroud)

到:

*.audio 
Run Code Online (Sandbox Code Playgroud)

保留原始文件名。

Wil*_*ard 7

您可以使用该rename命令。它不是可移植的,但它以不同的形式存在于不同的发行版中。

在 CentOS/RHEL 和 Fedora 中:

rename .mp4 .audio *.mp4
Run Code Online (Sandbox Code Playgroud)

应该做。从man renameCentOS 6 开始:

SYNOPSIS
       rename from to file...
       rename -V

DESCRIPTION
       rename  will  rename  the specified files by replacing the first occur-
       rence of from in their name by to.
Run Code Online (Sandbox Code Playgroud)

在 Ubuntu 和可能的任何 Debian 变体中:

rename 's/\.mp4$/.audio/' *.mp4
Run Code Online (Sandbox Code Playgroud)

应该这样做。从man renameUbuntu 14.04 开始:

SYNOPSIS
       rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]

DESCRIPTION
       "rename" renames the filenames supplied according to the rule specified
       as the first argument.  The perlexpr argument is a Perl expression
       which is expected to modify the $_ string in Perl for at least some of
       the filenames specified.  If a given filename is not modified by the
       expression, it will not be renamed.  If no filenames are given on the
       command line, filenames will be read via standard input.

       For example, to rename all files matching "*.bak" to strip the
       extension, you might say

               rename 's/\.bak$//' *.bak
Run Code Online (Sandbox Code Playgroud)