2

I'm trying to rename a bunch of files and folders.

I tried this command rename 's/test/test2/' but I got unable to execute /usr/bin/rename: Argument list too long

I searched a lot and tried different solutions but I'm not getting it.

The last one I tried was this one find . -type f -exec rename -n 's/test/test2/' ** {} \; which I also got the same error.

Thank you!

Edit: Also tried xargs -0 rename -n 's/test/test2/' ** and I got xargs: cannot fit single argument within argument list size limit

1

You want

find . -type f -exec rename -n 's/test/test2/' {} +

The -exec ... + form will put as many arguments as can fit, so it will invoke rename as few times as possible.

Your mistake was using find ... -exec and also putting ** on rename's argument list.

  • It works with the -n argument but if I take it out I got unable to execute /usr/bin/rename: Argument list too long however it lists all the files and folder it was supposed to change but saying No such file or directory – Kulcanhez Jul 21 at 20:36
0

It sounds to me like you have a file with an extremely long file name.

To find the top 5 longest file names in a given directory, use the following (replacing /etc with the path in question)

ls /etc | perl -e 'print sort { length($b) <=> length($a) } <>' | head -5

If you do have a filename that is absurdly long, you may be able to first rename it using the 'mv' command to a shorter name.

  • Maybe I have but I can't change it cause it would involve changing a lot of inner code. – Kulcanhez Jul 21 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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