[ファイル名].mp4 をすべて見つけて [ファイル名].audio [重複] の名前を変更します。

[ファイル名].mp4 をすべて見つけて [ファイル名].audio [重複] の名前を変更します。

そのため、ファイル内のオーディオを使用して2つの映画を一緒に追加するスクリプトがあります$1.audio。私がやりたいことは、ディレクトリ内のすべてのファイルの名前を次のように変更することです。

*.mp4 

到着する:

*.audio 

元のファイル名を保持してください。

ベストアンサー1

このコマンドを使用できますrename。移植性はありませんが、ディストリビューションによって異なる形で存在します。

CentOS/RHEL と Fedora の場合:

rename .mp4 .audio *.mp4

すべきこと。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.

UbuntuとDebianのバリエーションの場合:

rename 's/\.mp4$/.audio/' *.mp4

それは行わなければなりません。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

おすすめ記事