Linux command
perl-rename 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Rename with regex substitution
perl-rename 's/old/new/' [*.txt]
Lowercase filenames
perl-rename 'y/A-Z/a-z/' [*]
Uppercase filenames
perl-rename 'y/a-z/A-Z/' [*]
Add prefix
perl-rename 's/^/prefix_/' [*]
Add suffix before extension
perl-rename 's/(\.\w+)$/_suffix$1/' [*]
Preview changes
perl-rename -n 's/old/new/' [*.txt]
Replace spaces with underscores
perl-rename 's/ /_/g' [*]
Remove numbers from names
perl-rename 's/\d//g' [*]
说明
perl-rename renames files using Perl regular expressions. It's more powerful than basic mv for batch renaming. The expression modifies the $_ variable containing the filename. Common operations use s/// for substitution and y/// for transliteration. Perl's full regex syntax is available: character classes, backreferences, lookahead, and more. Multiple -e expressions chain together. Dry run mode (-n) shows changes without performing them. Always use this first to verify complex expressions. The tool handles special characters, spaces, and Unicode in filenames. Quoting expressions prevents shell interpretation. Different systems may call this command rename, prename, or file-rename. The underlying functionality is the same.
参数
- -n, --no-act
- Dry run, show what would happen.
- -v, --verbose
- Show renames as they occur.
- -f, --force
- Overwrite existing files.
- -0, --null
- Read null-terminated filenames from stdin.
- -d, --filename
- Rename filename only, not directory.
- -e _EXPR_
- Expression (can use multiple).
- --version
- Show version.
- --help
- Show help.
FAQ
What is the perl-rename command used for?
perl-rename renames files using Perl regular expressions. It's more powerful than basic mv for batch renaming. The expression modifies the $_ variable containing the filename. Common operations use s/// for substitution and y/// for transliteration. Perl's full regex syntax is available: character classes, backreferences, lookahead, and more. Multiple -e expressions chain together. Dry run mode (-n) shows changes without performing them. Always use this first to verify complex expressions. The tool handles special characters, spaces, and Unicode in filenames. Quoting expressions prevents shell interpretation. Different systems may call this command rename, prename, or file-rename. The underlying functionality is the same.
How do I run a basic perl-rename example?
Run `perl-rename 's/old/new/' [*.txt]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -n, --no-act do in perl-rename?
Dry run, show what would happen.