How to rename a file with a leading hyphen?
Tim Chase
plugaz at tim.thechases.com
Mon Feb 28 20:40:43 MST 2011
On 02/28/2011 09:12 PM, joe at actionline.com wrote:
> When I download images and ".MOV" files from digikam
> the file names all have a leading hyphen. I've been
> able to convert -filename.png files to filename.jpg
> but when I try to use 'mv' to rename -filename.MOV files
> to filename.MOV or filename.mov without the leading
> hyphen, it does not work.
>
> How can I rename these .MOV files to remove the leading
> hyphen (-) and to change the .MOV suffix to .mov ?
You can prefix with the path:
bash$ mv ./-file.png file.png
This could also be wrapped in a shell loop:
for fname in -*.png; do mv ./"${fname}" "${fname/#-/}"; done
to do multiple files with leading "-" characters. Note this will
cold-heartedly tromp any existing files with the non-leading-dash
if they exist beforehand.
Some GNU commands will also take "--" to mean "ignore any
option-looking things after this" so you might be able to get
away with
bash$ mv -- -file.png file.png
though I don't think "mv" is among the commands that do that.
-tim
More information about the PLUG-discuss
mailing list