I ran a perl script using
perl -p -i.bak -e "..." *.sh dir/*.sh
This created a copy of every file like
script.sh
script.sh.bak
I now want to restore from the .bak
files. How can I do this easily?
for file in *.sh.bak dir/*.sh.bak; do cp "$file" "${file//.bak}"; done
Or you could use mv
instead of cp
.
find -name '*.bak'|sed 's:.bak$::'|xargs -n 1 -I % cp %.bak %
Thanks for this fix.
I've been using a combo the code below to fix an 'eval(base64_decode' in Joomla sites.
find: grep -lr --include=*.php "eval(base64_decode" ./
remove: grep -lr --include=.php "eval(base64_decode" ./ | xargs sed -i.bak 's/eval(base64_decode[^;];/\n/g'
undo: find -name '*.bak'|sed 's:.bak$::'|xargs -n 1 -I % cp %.bak %