This is a test version of Biostars. For the public version, visit https://www.biostars.org.
rename files names in a directory based on list of names

Hi,

I am looking to rename all files in a directory based on a list of names in another file. Have any unix command or script?

unix

Hello Manoj!

We believe that this post does not fit the main topic of this site.

not related to bioinformatics. Just a basic linux Q

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

There is a unix program called "rename" that will help. Type man rename for details.

1 answer

I don't know if this is what you are looking for, but here is one example of unix command:

If you have a file "names.tab" with old and new names in tabulated format like that:

oldName1 NewName1
oldName2 NewName2

In the directory where you have the files you type:

IFS=$'\n'; for i in $(cat names.tab);do oldName=$(echo $i | cut -d $'\t' -f1);  newName=$(echo $i | cut -d $'\t' -f2); mv $oldName $newName;done

Log in to answer this question.