[英]linux rename multiple files using rename
I have a bunch of files (several thousand) called: 我有一堆文件(数千个):
output.temp.1.csv
output.temp.2.csv
output.temp.3.csv
etc. output.temp.1.csv
output.temp.2.csv
output.temp.3.csv
等
I would like them all to be renamed but having the .temp
removed 我希望将它们全部重命名,但是删除.temp
output.1.csv
output.2.csv
output.3.csv
etc. output.1.csv
output.2.csv
output.3.csv
等
I think rename
is what i need but not sure how to go about doing it 我认为rename
是我所需要的,但不确定如何去做
I tried: 我试过了:
rename 'output.temp' 'output', output.temp.*.csv
But this didn't work... 但这没有用...
Any advice on how to get this changed? 关于如何进行更改的任何建议?
Thanks... 谢谢...
You can use: 您可以使用:
rename 's/output\.temp/output/' output.temp.*.csv
This will rename 3 files to: 这会将3个文件重命名为:
output.1.csv
output.2.csv
output.3.csv
这是重命名所有文件的另一种解决方案:
ls -ltrh | grep -i output | awk '{print $9}' | awk -F\. '{print "mv",$0, $1"."$3"."$4}' | sh
Going off anubhava's answer, if all your files aren't in the same directory, you can use 摆脱了anubhava的回答,如果您所有的文件都不在同一目录中,则可以使用
find path/to/dir/ -name 'output.temp.*.csv' -exec rename 's/output\\.temp/output/' {} +
To rename all the files in path/to/dir
and any of its subdirectories. 重命名path/to/dir
及其任何子目录中的所有文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.