bash - How to run mv command run recursively in Linux -
my environment: bash 3.5 linuxredhat
i'm using following code rename of files in single directory.
for file in *.* ; mv "$file" "add_$file" ; done
now, want rename file recursively.and don't know how do.
the first ideas find don't work, because {} returns ./ command:
find . -type f -name "*.*" -execdir mv {} add_{} ";"
we need something, removes ./ in front works in subdirectories too.
echo 'f=$(basename "$1"); mv "$f" add_"$f";' > adhoc.sh chmod a+x adhoc.sh find . -type f -name "*.*" -execdir $pwd/adhoc.sh "{}" ";"
at least works gnu-find
. other finds might not have -execdir
command.
thanks skyking pointing error out.
for linux, might find version of 'rename' in repository, has installed , isn't part of standard installation. if rename commandline, worth effort. rename, specify regex substitute command , can test first:
find . -type f -exec rename -n "s/(.*)/add_\1/" {} ";"
Comments
Post a Comment