Moving or renaming a UNIX file starting with a dash
If you happen to create or rename a UNIX file system so it starts with a dash you'll get in a bit of trouble because most commands will get confused and will try to interpret it as an optional switch.
I had a file named "-h" and I was getting errors like this:
mv -h something_else
mv: illegal option -- h
usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory
The solution is pretty simple, just prepend "./" to the filename to indicate that the file is in the current directory or alternatively use the full path or a relative path to the file so syntactically it ends up being different to a command switch and you're done.
mv ./-h something_else
It works! :)
Written by Antonio Ognio
Related protips
1 Response
I ran into this before and it took me an embarrassingly long time to figure out. This is really helpful. Nice post!
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#