Sunday, April 17, 2005

Rename file starting with a dash(-)

If having problem renaming a file that starts with a dash:

Since the file name begins with a '-' it looks like an option to the
command. You need to force it to not look like an option. Put a ./
in the front of it. Or give it the full file name path. Or tell the
command you are through with options by using the double dash to end
all option processing. This is common to most traditional UNIX
commands.

cp ./* /some/folder
cp -- * /some/folder

And the same for other utilities too.

mv ./-stuff differentstuff
mv -- -stuff differentstuff

8 comments:

Anonymous said...

Thanks, this was frustrating me

Anonymous said...

Thanks for this (should have been obvious) solution.

Anonymous said...

Thanks. That really helped me a lot.

Giovanni said...

Thank you!

Anonymous said...

thank you very much.
Very useful

LC Chong said...

To batch rename files starting with hyphen:

rename 's/-//' ./*

Anonymous said...

Thanks for posting this, and Google helping me find it. :)

Anonymous said...

Wow, ten years of linux administration and this stumped me for a bit! I need more caffeine.

Thanks for the post, mate!