1

I have a directory full of file names that need to be changed. I don't need to simply rename a suffix or prefix, but rather to completely rename the files.

I have the new file names contined a file called new_names.

What command can I use to read the names contained in new_names & rename the files in a directory?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
  • 1
    Worth you updating the question to include an example directory listing, contents of new_names file, and the expected results. – steve Dec 15 '16 at 20:32
  • 5
    I just found a solution that worked: paste -d' ' <(ls *) ../output/new_filenames | xargs -n2 mv Here's the link to where I found it. http://unix.stackexchange.com/questions/152656/rename-a-list-of-files-according-to-a-text-file – freezing_up_north Dec 15 '16 at 21:18

1 Answers1

1

You can use this to generate a list of mv commands:

paste /path/to/new_names <(ls /path/to/files | grep -v new_names) | awk '$2 !~ /^$/ {print "mv " $2,$1}'

If it looks good, then you can execute it with:

cd /path/to/files
$( paste /path/to/new_names <(ls /path/to/files | grep -v new_names) | awk '$2 !~ /^$/ {print "mv " $2,$1}' )
DopeGhoti
  • 76,081