2

I am using the 'rename' command to rename a set of files; for example:

    inputcac1010.inp.log  inputcac1110.inp.log  inputcac1210.inp.log  inputcac1310.inp.log
    inputcac1020.inp.log  inputcac1120.inp.log  inputcac1220.inp.log  inputcac1320.inp.log
    inputcac1030.inp.log  inputcac1130.inp.log  inputcac1230.inp.log  inputcac1330.inp.log
    inputcac1040.inp.log  inputcac1140.inp.log  inputcac1240.inp.log  inputcac1340.inp.log
    inputcac1050.inp.log  inputcac1150.inp.log  inputcac1250.inp.log  inputcac1350.inp.log
    inputcac1060.inp.log  inputcac1160.inp.log  inputcac1260.inp.log  inputcac1360.inp.log
    inputcac1070.inp.log  inputcac1170.inp.log  inputcac1270.inp.log  inputcac1370.inp.log
    inputcac1080.inp.log  inputcac1180.inp.log  inputcac1280.inp.log  inputcac1380.inp.log
    inputcac1090.inp.log  inputcac1190.inp.log  inputcac1290.inp.log  inputcac1390.inp.log
    inputcac1100.inp.log  inputcac1200.inp.log  inputcac1300.inp.log  inputcac1400.inp.log

must be renamed to

    inputcac1010.log  inputcac1110.log  inputcac1210.log  inputcac1310.log
    inputcac1020.log  inputcac1120.log  inputcac1220.log  inputcac1320.log
    inputcac1030.log  inputcac1130.log  inputcac1230.log  inputcac1330.log
    inputcac1040.log  inputcac1140.log  inputcac1240.log  inputcac1340.log
    inputcac1050.log  inputcac1150.log  inputcac1250.log  inputcac1350.log
    inputcac1060.log  inputcac1160.log  inputcac1260.log  inputcac1360.log
    inputcac1070.log  inputcac1170.log  inputcac1270.log  inputcac1370.log
    inputcac1080.log  inputcac1180.log  inputcac1280.log  inputcac1380.log
    inputcac1090.log  inputcac1190.log  inputcac1290.log  inputcac1390.log
    inputcac1100.log  inputcac1200.log  inputcac1300.log  inputcac1400.log

I used

rename 's/inp\.log/log/' *.inp.log

It doesn't seem to work. I renamed them in a different way by reading the file names and using sed, but I am quite confused as to why this command didn't work in my case!!! Could anyone clarify? Thanks!

7
  • 1
    YOur rename command works for me. Oct 3, 2014 at 19:09
  • 1
    What about your command didn't work? Did it do anything? Without more information we certainly can't help you. Oct 3, 2014 at 19:10
  • 1
    unix.stackexchange.com would be a better site for this question
    – Barmar
    Oct 3, 2014 at 19:12
  • It doesn't do anything. I am more curious as to why it didn't work, as it looks pretty trivial. Please have a look at the screenshot above!
    – madchemist
    Oct 3, 2014 at 19:16
  • 1
    @Pradeep There are two major versions. One from util-linux one from perl related libraries. You're looking for the perl one. Oct 3, 2014 at 20:08

1 Answer 1

15

You have the version of rename that takes arguments like this:

rename inp.log log *.inp.log

I usually just use a loop; performance isn't a big issue, because how often do you really need to rename lots of files at once?

for f in *.inp.log; do
    mv "$f" "${f%.inp.log}.log"
done
4
  • That solves the problem. Thanks! It is surprising that different versions work very differently, especially linux utilities!
    – madchemist
    Oct 3, 2014 at 19:28
  • 4
    They aren't different versions so much as two completely separate programs with the same name. There's no standard that either needs to conform to.
    – chepner
    Oct 3, 2014 at 19:31
  • This does not answer the question which is about investigating why does the rename tool not work in same cases. Dec 21, 2021 at 16:08
  • 1
    There is no single 'rename' tool; as I said, there are two unrelated tools that do similar things that just happen to use the same name. If you don't realize which tool you are actually using and try to use it as the other one, it will likely fail. (If it doesn't fail, then it's due to the two programs behaving identically by coincidence rather than by design or conformance to a nonexistent specification.)
    – chepner
    Dec 21, 2021 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.