Remove all instances of _000 from multiple files

filesrecursiverenamescripting

Had to recover my music library from a HDD which died…. got everything I wanted but all music track names have _000 added at the end.

I really don't fancy going through 8000 individual music tracks and choosing to rename in order to remove the _000 string

How can I search the entire Music folder containing all the album sub-directories and remove every instance of _000 on all the individual track names?

Best Answer

Although mikesrv solution is much better and safer I think this can be done also with rename:

find Music/ -type f -name '*_000' -print0 | xargs -r0 rename -v '_000' ''

But there are still potential problems as mentioned, for example album_00020_000 will be renamed to album20 which obviously is not the desired behaviour.
I think on debian distribution was a perl tool rename which could do it. But unfortunately I can not find a way how to install it. So I found following perl script here which can suffice:

#!/usr/bin/perl -w
# rename - Larry's filename fixer
$op = shift or die "Usage: rename expr [files]\n";
chomp(@ARGV = <STDIN>) unless @ARGV;
for (@ARGV) {
    $was = $_;
    eval $op;
    die $@ if $@;
    rename($was,$_) unless $was eq $_;
}

So you can make this script executable and run:

find Music/ -type f -name '*_000' | /path_to_script/rename.pl 's/_000$//'
Related Question