Find files, rename in place unix bash Find files, rename in place unix bash unix unix

Find files, rename in place unix bash


The GNU version of find has an -execdir action which changes directory to wherever the file is.

find . -name '*.java' -execdir mv {} test.java \;

If your version of find doesn't support -execdir then you can get the job done with:

find . -name '*.java' -exec bash -c 'mv "$1" "${1%/*}"/test.java' -- {} \;


If your find command (like mine) doesn't support -execdir, try the following:

find . -name "*.java" -exec bash -c 'mv "{}" "$(dirname "{}")"/test.java' \;