Saturday, March 24, 2018

Rename multiple files in one command

If you want to rename multiple files, the trusty old Unix "mv" command can't help as it can rename only one file at a time.
This requires us to bring out something different from our Unix arsenal - the "rename" command!
Use the rename command in conjunction with find to rename multiple files:
find /source_folder/to/search/in/ -name 'myapp*.log.201*' -exec rename -v .log. .oldlog. {} \; >> /temp/rename.log

Here we are searching for files named 'myapp*.log.201*' and renaming them to 'myapp*.oldlog.201*'
In case you need to do this on multiple servers, use the for loops trick!

No comments:


Related Posts Plugin for WordPress, Blogger...