我有一堆像这样的文件:
file123.txt.452
file456.txt.098
file789.txt.078
如何从文件名中删除第二个点和末尾的数字?
我尝试使用“rename”命令,但是我的正则表达式可能不正确:
rename 's/txt.*/txt/' *
我有一堆像这样的文件:
file123.txt.452
file456.txt.098
file789.txt.078
rename 's/txt.*/txt/' *
尝试使用rename 's/txt\..+/txt/' *
命令。
\.
代表字面上的点,.+
代表其后的任何字符。
实际命令名称取决于您的系统。它可能是rename
、file-rename
、perl-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.
类似于:
for f in *.txt.*; do
g=${f%.txt.*}.txt
mv $f $g
done
string.replace("(.+\\.txt)(.+)", "$1")
rename
命令的存在和用法。这对我也可能很有用... - Sebastian Simon