I have several files under a directory whose names are of the form *.foo.bar. I would like to write a bash script to rename each of these files by removing the .foo part.For example, suppose that issuing tree ~/dir/ returns/home/user/dir/|- george.foo.bar|- john.foo.bar|- paul.foo.bar|- ringo.foo.bar|- subdir   |- jimmy.foo.bar   |- robert.fooThen running script ~/foo/ should alter the contents of ~/foo to/home/user/dir/|- george.bar|- john.bar|- paul.bar|- ringo.bar|- subdir   |- jimmy.bar   |- robert.foo
Bash script that removes part of a filename in every file under a directory
bash;shell script;rename
You can use parameter expansion mechanismshopt -s globstarfor file in **/*foo.bar; do    prefix=${file%.foo*}    suffix=${file##*.foo}    mv -v -- $file $prefix$suffixdoneThe ${file%.foo*} removes matching suffix (leaving only prefix), and ${file#*.foo} removes prefix (leaving suffix). The double star glob (**) is needed to traverse all subdirectories and setopt -s globstar allows that glob.