peetaur

bash find and move script

May 27th, 2013
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.54 KB | None | 0 0
  1. test data:
  2. ========
  3. $ find -type f
  4. ./foo/bar3
  5. ./foo/blah3.jpg
  6. ./foo/blah2.JPG
  7. ./blah.JPG
  8.  
  9. script:
  10. ========
  11. # the next IFS= line makes the find work for spaces,
  12. # so only new lines in find output will separate file names
  13. IFS=$'\n'
  14. for name in $(find -type f -name "*.JPG"); do
  15.      oldname=$(basename "$name")
  16.      dir=$(dirname "$name")
  17.      newname=$(echo "$oldname" | sed -r "s/\.JPG/.jpg/")
  18.      echo "mv \"$name\" \"$dir/$newname\""
  19. done
  20.  
  21. output:
  22. ========
  23. mv "./foo/blah2.JPG" "./foo/blah2.jpg"
  24. mv "./blah.JPG" "./blah.jpg"
Advertisement
Add Comment
Please, Sign In to add comment