Rename the list of files with names from another list.

I have a list similar to the one below in the lista.txt file:

mickey
donald
daffy 
bugs

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

I want to iterate through these files:

filename1 => mickey 
filename2 => donald ...

Can you provide me with a working sample code for this task?

+7
source share
5 answers

This is not my style for your work. I would prefer you to publish what you have already tried, so I can help you debug it, but this problem is so simple that I will still bite.

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

Using bash arrays:

files=( * )
i=0
while read -r new_name; do
  mv "${files[$i]}" "$new_name"
  (( i++ ))
done < lista.txt
+4
source
let "count=1"

for newname in $(cat lista.txt); do
  mv "filename$count" "$newname"
  let "count++"
done
+3

, flac "filelist.txt" :

while read -u 9 filename ; do  
    read -u 8 newname 
    echo mv "$filename" "$newname" 
done 9<<<"$(ls -1 *flac)" 8< filelist.txt

.flac 9 " ", .list 8 " ".

, ( "-u 9" "9" ), , stdin ; , .

" " .

+1

Linux krename, javascript. .

  1. Krename
  2. javascript , :

    var files = [
        "Mickey",
        "Donald",
        "Duffy"
    ];
    
    function rename(){
      // krename_index is one of many special variables which can be added via ui
      return files[krename_index];
    }
    

, , , .

  1. , :

    [js; rename()]

$ . "", .

  1. , .
0
source

All Articles