重命名 此工具最初由Perl的父亲Larry Wall编写. I have three files namedfile1.txtfile2.txtfile3.txtI am trying to rename them tomynewfile-1.txtmynewfile-2.txtmynewfile-3.txtHow would I go about this using regular expressions? 解决方案 Like this :rename -n 's/^file/mynewfile-/' *.txtor from comments :rename -n 's/^file(\d+)/mynewfile-${1}-test/' *.txt ___ ____ ^ ^ capturing group | captured groupDrop -n switch when the output looks good to rename for real. There are other tools with the same name which may or may not be able to do this, so be careful.The rename command that is part of the util-linux package, won't.If you run the following command (GNU)$ renameand you see perlexpr, then this seems to be the right tool.If not, to make it the default (usually already the case) on Debian and derivative like Ubuntu :$ sudo apt install rename$ sudo update-alternatives --set rename /usr/bin/file-renameFor archlinux:pacman -S perl-renameFor RedHat-family distros:yum install prenameThe 'prename' package is in the EPEL repository.For Gentoo:emerge dev-perl/renameFor *BSD:pkg install p5-File-RenameFor Mac users:brew install renameIf you don't have this command with another distro, search your package manager to install it or do it manuallyOr you can use perl CPAN:cpan -i File::RenameOld standalone version can be found hereman renameThis tool was originally written by Larry Wall, the Perl's dad. 这篇关于使用正则表达式重命名文件-Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-16 08:01