7

I have a 100+ files that start with a dash (-). I need to know how to do two things:

Example: -20200622_142237.jpg (File extensions vary, but all have the dash at the beginning.)

  1. How do I list (ls) files that start with this dash? Bash seems to think I'm trying to use another parameter. I've tried using single quotes, double quotes and - in front. Nothing seems to work.

  2. How do I rename all of these files at the same time? The intent is to rename them without the dash at the beginning.

NOTE: I don't want to change the underscore (_). I just want to remove the dash (-) at the beginning of the file.

Lastly, I've already tried this possible solution posted previously, but it does not work.

11

You can usually use -- to indicate the end of command options. So:

  1. ls -- -*

  2. (with the perl-based rename command) rename -n 's/^-//' -- -*

Remove the -n once you are happy that it is doing the right thing.

See also:

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.