Renaming files with –– at the start

I’m making a post about this because I ran into this today and I couldn’t remember how to rename a file starting with — (two or double hyphens) in Linux (e.g. –index.html). The customer has obviously used a Windows FTP client to rename index.html to –index.html so it is out of their way, and now me, the server administrator or company sysadmin, has come along with my migration script to relocate it and it has fallen over, crashed, and burned!

When you try and rename it the following is given:

$ mv ––index.html index.html.renamed
mv: unrecognized option `––index.html’
Try `mv ––help’ for more information.

I also tried delimiting it the normal way, but it wouldn’t work either:

mv \–\–index.html index.html.renamed

The correct way to rename it is:

mv ./––index.html index.html.renamed

Because –– has special meaning, you can’t delimit it with a simple backslash (\), you have to put a path reference in there to delimit it. So my path working directory (pwd) was /home/user/data/ where the file was located, so I could use ./ to reference the current pwd. The other option is to put the full path in:

mv /home/user/data/––index.html index.html.renamed

Hopefully this helps out some other Linux server administrator out there who’s mind it has slipped.

Similar Posts:

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)
This entry was posted in Linux, Server Administration, SSH. Bookmark the permalink.

What are your thoughts?