Search code examples
bashfilefindmv

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


Solution

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