[SOLVED] Using rename to replace a string that begins with a -
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Using rename to replace a string that begins with a -
Sometimes I want to use rename on a group of files to replace a string that begins with a -. No kind of quoting keeps rename from treating the - as an option instead of an argument.
First off, something like the DASH should be prefixed with a delimiter, such as backslash. The rename command always throws me for a loop and I usually have to web search for an example.
First, I never use rename. I always do name changes either on the command line or from a script, and only after testing and verifying against a worthless copy.
Second, have you tried escaping that character? ie
Code:
mv -- "-wobble.dat" "drabble.dat"
may work. The -- tells the program that nothing after that is a command line option.
CORRECTION: the "rename" on my systems do not use GNU standard. It is also not very intelligent in dealing with quotes and escapes. Try using GNU utilities and a script instead.
Quoth Mr rtmistler: 'Are you using the rename(1) command?'
Yes.
Quoth Mr rtmistler: 'First off, something like the DASH should be
prefixed with a delimiter, such as backslash.'
I thought I communicated that I had tried that with my original message.
Quoth Mr wpeckham: 'I never use rename'
Congratulations.
Quoth Mr wpeckham: 'I always do name changes either on the command line or from a script'
When I can't get rename to work, that's what I do as well.
Quoth Mr wpeckham: 'have you tried escaping that character?'
Yes.
Quoth mr wpeckham: '-- tells the program that nothing after that is a command line option.'
I didn't know that, after all these years... That works. Thanks.
He didn't quote it, so it wouldn't make a difference. However, he should have quoted it, and if he had, it would have mattered, so it's a good suggestion.
He didn't quote it, so it wouldn't make a difference. However, he should have quoted it, and if he had, it would have mattered, so it's a good suggestion.
better safe then sorry -- someone -- I think that guy over there says
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.