List & rename files that start with dash/hyphen (-)

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.


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:

  • How do I use filenames that start with a dash “-” as command arguments?