Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename large number of files

I have a directory with files like this

a.JPG
b.JPG
c.JPG

I would like to perform something like this

git mv a.JPG a.jpg

I tried using xargs and other tools but nothing seems to work.

like image 480
Nick Vanderbilt Avatar asked Jun 05 '10 16:06

Nick Vanderbilt


2 Answers

To rename file extensions from .JPG to lowercase. This uses git mv, so that git history is preserved.

find . -name "*.JPG" | xargs -L1 bash -c 'git mv $0 ${0/JPG/jpg}'
like image 55
Damien Bezborodow Avatar answered Oct 12 '22 19:10

Damien Bezborodow


Whether or not you can just change the case of the file will depend on your filesystem. Even if it works on your filesystem, you could cause problems for other people updating. You'll be best renaming them, committing them, then renaming them back. Change everything to *.tmp with the following bash script:

for i in *.JPG; do mv $i ${i%.JPG}.tmp; done

Then move them all in git. You can use a similar command, but I would recommend checking out guess-renames which will help with the move.

Then rename them all back to *.jpg with a similar process.

like image 41
wbyoung Avatar answered Oct 12 '22 20:10

wbyoung