JosefJezek
9/26/2013 - 8:45 AM

How to rename filenames

How to rename filenames

How to rename filenames

  • rename Dell Fujitsu *
  • Remove all blank space with rename command:
  • rename "s/ *//g" *.mp3
  • To convert all uppercase filenames to lowercase:
  • rename 'y/A-Z/a-z/' *
  • Rename files with spaces to dashes
  • rename "y/ /-/" *
  • Recursively
shopt -s globstar
rename -n 's/special/regular/' **

Remove the -n switch when your tests are OK

file.1.png
file.2.png
…
file.10.png
…
file.1000.png
file.1001.png
…
How can I pad the number to 4 digits? It should end up like this:

file.0001.png
file.0002.png
…
file.0010.png
…
file.1000.png
file.1001.png
…

rename 's/(\d+)/sprintf"%04d",$1/ge' file.*.png

http://unix.stackexchange.com/questions/21425/padding-a-number-in-a-filename-to-a-fixed-length