Rename a list of file with names from another list

Fabio B. picture Fabio B. · Jul 11, 2011 · Viewed 8.9k times · Source

I have a list like the following, in a file called lista.txt:

mickey
donald
daffy 
bugs

I have a folder containing many files: filename1, filename2, ... filenameN.

I want to iterate through those files to achieve:

filename1 => mickey 
filename2 => donald ...

Can you provide me working sample code for this task?

Answer

Flimzy picture Flimzy · Jul 11, 2011

It's not my style to do your work for you. I'd rather you post what you've already tried, so I can help you debug it, but this problem is so easy, I'm going to bite anyway.

x=1; for y in $(cat lista.txt); do mv $y filename$x; let x=$x+1; done