New function labeled rex() servers a single purpose. Replace the file extensions of multiple file at once. File extensions usually does not quite matter in bash, but there is a few cases when one might needs to and this function simplifies the process from multiple commands into one.
The Function
function rex() {
about 'mass replace of the extension of multiple files'
param '1: extension to replace'
param '2: new extenstion'
example 'rex txt md'
group 'base'
local ext2replace="${1:-}"
local newext="${2:-}"
local files=(`ls *.$ext2replace`)
for file in "${files[@]}"; do mv "$file" "${file/%.$ext2replace/.$newext}"; done
}
How Has This Been Tested?
Created multiple test files with different extensions, than proceeded to use rex to only change the specified extension which worked flawlessly
Testing Environment
OS : Debian GNU/Linux 12 (bookworm) x86_64
VER: 6.1.0-21-amd64
Bash Ver: 5.2.12
Computer: Lenovo Thinkpad P52s
Screenshots (if appropriate):
Types of changes
[ ] Bug fix (non-breaking change which fixes an issue)
[x] New feature (non-breaking change which adds functionality)
[ ] Breaking change (fix or feature that would cause existing functionality to change)
Checklist:
[x] My code follows the code style of this project.
[x] If my change requires a change to the documentation, I have updated the documentation accordingly.
[x] I have read the CONTRIBUTING document.
[x] If I have added a new file, I also added it to clean_files.txt and formatted it using lint_clean_files.sh.
[ ] I have added tests to cover my changes, and all the new and existing tests pass.
Description
New function labeled
rex()
servers a single purpose. Replace the file extensions of multiple file at once. File extensions usually does not quite matter in bash, but there is a few cases when one might needs to and this function simplifies the process from multiple commands into one.The Function
How Has This Been Tested?
Created multiple test files with different extensions, than proceeded to use
rex
to only change the specified extension which worked flawlesslyTesting Environment
Screenshots (if appropriate):
Types of changes
Checklist:
clean_files.txt
and formatted it usinglint_clean_files.sh
.