How do I Remove Specific Characters From File Names Using BASH

Bash can do sed-like substitutions:

for file in *; do mv "${file}" "${file/000/}"; done

Try this (this works in plain old Bourne sh as well):

for i in *000.tga
do
    mv "$i" "`echo $i | sed 's/000//'`"
done

Both arguments are wrapped in quotes to support spaces in the filenames.


A non-bash solution, since I know two speedy posters have already covered that:

There's an excellent short perl program called rename which is installed by default on some systems (others have a less useful rename program). It lets you use perl regex for your renaming, e.g:

rename 's/000//' *000*.tga

Use rename, maybe you need to install it on linux, Its python script

rename (option) 's/oldname/newname' ...

so you can use it like

rename -v 's/000//' *.tga

that means we are instructing to replace all files with .tga extension in that folder to replace 000 with empty space. Hope that works

You can check this link for more info and here