Rename a list of files according to a text file

rename

I have a list of files in a folder, which I will like to rename according to a textfile. For example:

These are the 5 files in the folder.

101_T1.nii
107_T1.nii 
109_T1.nii
118_T1.nii
120_T1.nii

I will like to have them rename using a text file containing a list of new filenames in the same order, without the extension .nii:

n01
n02
n03
n04
n05

How may I go about doing so?

Best Answer

one liner, this command reads the 'list' txt and parses for each line a file.

for file in *.nii; do read line;  mv -v "${file}" "${line}";  done < list
Related Question