When you want to rename a directory full of files from fooo2 to foo2, you’re first thought is using sed.. why, when rename
is easier?
First things first.. there’s different syntax if you’re using Ubuntu based and Red Hat / CentOS.. so pay attention.
We have a directory full of these files:
fooo1.txt
fooo2.txt
fooo3.txt
fooo4.txt
fooo5.txt
Whoever created these misspelled foo.. so we need to fix it so they’re all foo?.txt instead.
ie: from fooo1.txt to foo1.txt
We’re going to use rename
to accomplish this.
In Red Hat / CentOS, use this syntax.
1 |
rename fooo foo fooo* |
In Ubuntu, use this syntax.
1 |
rename s/fooo/foo/ fooo* |
If you did it right, you now have:
foo1.txt
foo2.txt
foo3.txt
foo4.txt
foo5.txt
(and the boss is happy!)