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.)
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.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.
1 Answer
You can usually use -- to indicate the end of command options. So:
ls -- -*(with the perl-based
renamecommand)rename -n 's/^-//' -- -*
Remove the -n once you are happy that it is doing the right thing.
See also: