Guest User

Untitled

a guest
May 25th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Rename filename extensions:
  4. #
  5. # Example: ./ren txt xml
  6. #
  7. # Script needs to be set as executable using:
  8. # > chmod a+x ren
  9. #
  10.  
  11. # There must be two command line parameters
  12. # If not, display message and exit
  13. if [ $# -ne 2 ]
  14. then
  15. echo Usage: $0 old_extension new_extension
  16. echo Example: $0 txt xml
  17. exit 1
  18. fi
  19.  
  20. # How many file were renamed
  21. filecount=0
  22.  
  23. # For each matching extension…
  24. for filename in *.$1
  25. do
  26. # Move file Strip off part of filename matching 1st argument,
  27. # then append 2nd argument.
  28. mv $filename ${filename%$1}$2
  29. ((filecount++))
  30. done
  31.  
  32. echo Renamed $filecount files
  33.  
  34. exit 0
Add Comment
Please, Sign In to add comment