bash rename all files which meet pattern


/ Published in: Bash
Save to your folder(s)

Just a basic bash snippet, of interest is the substring replacement, imo.


Copy this code and paste it in your HTML
  1. #!/usr/bin/env bash
  2.  
  3.  
  4. for file in .* *; do
  5. # skip current/previous dirs and unresolved wildcards
  6. if [[ "$file"=="grimm*" ]]
  7. then
  8. old="grimm.3"
  9. new="Grimm.S03E"
  10. newname=${file/grimm.3/Grimm.S03E}
  11. mv "$file" ./$newname
  12. # ${string/substring/replacement}
  13. fi
  14. done

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.