I have in a directory some files:

other files

How can I remove the _ from the beginning of each file that begins with this character ? I only want the first _ removed as some files can have underscore at other position. A one-line command would be awesome.

As a mention, I use CentOS 7 and using mv is not mandatory but that's what came to my mind.

| improve this question | | | | |

Try this one-liner (the echo shows what the command will do):

for name in *; do echo mv ${name} ${name##_} ; done

${name##_} returns the $name variable without the _ at the beginning of the variable

When you are happy, remove the echo from the command.

Good luck!

| improve this answer | | | | |

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.