删除部分文件名

Removing part of the file names

我有一堆这样的文件:

file123.txt.452
file456.txt.098
file789.txt.078

如何删除文件名中的第二个点和末尾的数字?

我尝试使用 rename,但我认为我的正则表达式不正确:

rename 's/txt.*/txt/' *

试试这样的正则表达式:

string.replace("(.+\.txt)(.+)", "")

类似于:

for f in *.txt.*; do
    g=${f%.txt.*}.txt
    mv $f $g
done

尝试rename 's/txt\..+/txt/' *

\. 用于文字点,.+ 用于其后的任何内容。

命令的实际名称depends on your system。它可以是 renamefile-renameperl-rename 或其他。上面代码使用的 rename 命令在其 man 条目中有这个:

NAME
       rename - renames multiple files

SYNOPSIS
       rename [-bfilnv] [-B prefix] [-S suffix] [-V method] [-Y prefix] [-z suffix]
       [--backup] [--basename-prefix=prefix] [--dry-run] [--force] [--help] [--no-stdin]
       [--interactive] [--just-print] [--link-only] [--prefix=prefix] [--suffix=suffix]
       [--verbose] [--version-control=method] [--version] perlexpr [files]...

DESCRIPTION
       rename renames the filenames supplied according to the rule specified as the first
       argument.  The argument is a Perl expression which is expected to modify the $_ string
       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.