Renaming multiple Linux files

Asked

Viewed 368 times

2

I have several files:

xaa.txt xab.txt xac.txt xad.txt até xcn.txt

I need to rename all files to:

nome1.txt nome2.txt nome3.txt etc...

In order, that is, xaa.txt must be the name1.txt xab.txt must be Nome2.txt and so on

It is possible to rename by terminal at once?

  • It matters the order that will be renamed?

  • Hello @Felipeavelar, it matters yes. xaa.txt must be name1.txt xab.txt must be Nome2.txt and so on.

  • 3

    Yes, it is possible. go to the directory where the files are located and run the following command on the terminal. var=$(ls -1 | Sort -h); number=0; for i in $var; do mv $i i nome_$number; number=$[number + 1]; done explanation: > var=$(ls -1 | Sort -h) will get all the files you have in the directory in alphabetical order. > number=0 to start renaming from 0. > for i in $var; from mv $i nome_$number; number=$[number + 1]; done .

  • @Alessandroschneider! It worked! Thank you!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.