I have a lot of files that have a shared pattern in their name that I would like to remove. For example I have the files, "a_file000.tga" and "another_file000.tga". I would like to do an operation on those files that would remove the pattern "000" from their names resulting in the new names, "a_file.tga" and "another_file.tga".
The tr command (short for translate) is used to translate, squeeze, and delete characters from a string. You can also use tr to remove characters from a string.
To remove the first and last character of a string, we can use the parameter expansion syntax ${str:1:-1} in the bash shell. 1 represents the second character index (included). -1 represents the last character index (excluded). It means slicing starts from index 1 and ends before index -1 .
Bash can do sed
-like substitutions:
for file in *; do mv "${file}" "${file/000/}"; done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With