mv \~ ~/albumName.rar
mv '~' ~/albumName.rar
mv ./~ ~/albumName.rar
You can always protect a character that has a special meaning in the shell by putting a backslash before it.
You can always tell the shell to interpret a sequence literally by putting it inside single quotes. The only character that you can't put inside such a literal string is the single quote itself, since it indicates the end of the literal string. You can use
'\'' instead; it means “end of literal, the character
', start of literal”, but you can think of it as a weird way of putting a single quote inside a literal string within single quotes.
~ is only special at the beginning of a path, so if you put a directory indication,
~ will be the name of the file in this directory.
Note that if the file name begins with
-, only the last of these three methods will work. This is because
- is not special to the shell; it has a special meaning to the command: it indicates an option. Another way of protecting
- against this special meaning is to put the special option
-- before it:
-- on a command line indicates the end of the options, only file names (or other non-option arguments) may come after it.
Note also that the command you show should have copied the file to your home directory, as the
~ character should have been interpreted by the shell. It's possible that you mistyped and created a file that's not called
ls -q or
ls -Q to see if the file name contains an unprintable character. If that doesn't provide any visual indication, try
ls | od -t o1, which will show the octal code for each byte in the file name. In ksh, bash or zsh, you can use
$'\123' in a command line to specify a character by its octal code. Alternatively, you may be able to find a pattern that matches the file. For example, if you determine that the length of the file name is 3, and that the only other files whose length is 2 are
bar, you can move the file with
mv ./[^bf]?? ~/albumName.rar
And if you're willing to use the mouse and the name is composed of printable characters that you don't know how to type: copy-paste the file name from the output of