Linux command
file-rename 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Rename using Perl expression
file-rename 's/old/new/' [files]
Rename to lowercase
file-rename 'y/A-Z/a-z/' [files]
Dry run to preview changes
file-rename -n 's/pattern/replacement/' [files]
Replace spaces with underscores
file-rename 's/ /_/g' [files]
Add prefix to files
file-rename 's/^/prefix_/' [files]
Change file extension
file-rename 's/\.jpeg$/.jpg/' [*.jpeg]
Remove numbering prefix from files
file-rename 's/^\d+_//' [files]
说明
file-rename (also known as rename or prename) renames multiple files using Perl regular expressions, providing powerful pattern-based transformation capabilities. Unlike simple mv operations, it can apply complex substitutions, case conversions, and pattern matching across multiple filenames simultaneously. The tool supports the full Perl regex syntax including capture groups, look-ahead/look-behind assertions, and transliteration operations. Common uses include batch renaming, removing or replacing characters, changing file extensions, and standardizing filename formats. file-rename's dry-run mode (-n) allows preview of changes before execution, preventing accidental destructive operations. The force flag (-f) enables overwriting existing files when name collisions occur.
参数
- -n, --no-act
- Dry run, show what would happen.
- -v, --verbose
- Print names of files renamed.
- -f, --force
- Overwrite existing files.
- -0, --null
- Expect null-terminated input from stdin (for use with find -print0).
- -d, --filename
- Rename only the filename component, not the directory part.
- -e _expression_
- Apply expression to filename. Multiple -e options can be chained.
FAQ
What is the file-rename command used for?
file-rename (also known as rename or prename) renames multiple files using Perl regular expressions, providing powerful pattern-based transformation capabilities. Unlike simple mv operations, it can apply complex substitutions, case conversions, and pattern matching across multiple filenames simultaneously. The tool supports the full Perl regex syntax including capture groups, look-ahead/look-behind assertions, and transliteration operations. Common uses include batch renaming, removing or replacing characters, changing file extensions, and standardizing filename formats. file-rename's dry-run mode (-n) allows preview of changes before execution, preventing accidental destructive operations. The force flag (-f) enables overwriting existing files when name collisions occur.
How do I run a basic file-rename example?
Run `file-rename 's/old/new/' [files]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -n, --no-act do in file-rename?
Dry run, show what would happen.