-2

I would like to change several files name in my current directory, like this for example :
test1
test2
test3

And I would like to rename every file with a command (mv I think) to have that (for example) :
foo1
for2
foo3

Can you help me ? Thanks in advance

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
Tjamat
  • 193
  • 1
  • 11
  • -1 very low quality of question, bad tags, batch is not bash, shell is not Linux shell, a shell is a shell. – ElektroStudios Apr 30 '13 at 08:56
  • My tags were wrong, but it doesn't change the quality of the question. and you don't answer it. inappropriate aggressiveness... – Tjamat Apr 30 '13 at 09:37
  • At least I've commented my downvote. A question without specifying the Language/OS using a comment or a tag or a code exmaple to give the opportunity to the users to understand what you really need is a low quality, I'm not agressive. PS: Sorry for my english. – ElektroStudios Apr 30 '13 at 12:44
  • This is my first comment ever and I'm new on this website and on this environment ... Shell / batch were enough to solve the question. If I knew everything I wouldn't have asked the question... – Tjamat Apr 30 '13 at 13:14
  • No need to be a experimented user to make a good question. regards. – ElektroStudios Apr 30 '13 at 13:29
  • No but lack of experience can cause people to ask unaccurate questions. like me. doesn't mean the question is "very low quality" – Tjamat Apr 30 '13 at 13:44

2 Answers2

1

Syntax :

rename oldname newname *.files

For example : rename all *.bak file as *.txt, enter:

$ rename .bak .txt *.bak
Anil
  • 1,028
  • 9
  • 20
  • I didn't knew this tool.
    Hope cygdrive supports it. Thanks !
    – Tjamat Apr 30 '13 at 07:38
  • Looks like it doesn't exist on cygdrive, I only have "renameutils" package with commands qmv, imv, and icp. Or maybe there's a trick with batch to do that ? – Tjamat Apr 30 '13 at 07:50
1

You can do this with a loop and parameter expansion, like this:

for f in test*; do mv "$f" "${f/test/foo}"; done

See also http://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html

spbnick
  • 5,025
  • 1
  • 17
  • 22