Tags
Tags

Reputation: 172

Find all matching files and renaming in bash shell

Basically I'm adding a temporary ~ at end of my file to know I've touched them. So they look like file.txt~. I can always change the extension if it makes my next step easier which is renaming them to file.txt.old.

My approach was to do a find directory -name '*~' than piping to mv. Im just not sure how to handle the ~.

Any pointer would be appreciated

Upvotes: 1

Views: 68

Answers (1)

Rafael
Rafael

Reputation: 7746

find -name '*~' | while read file
do 
    mv -v $file $(echo $file | sed 's@\(.*\)~@\1.old@')
done

Upvotes: 1

Related Questions