Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

So I have downloaded a music album from aMule and it is located in the .aMule/Incoming directory. I tried to move it out with the following command:

 mv albumName.rar ~

This left me with a file ~ in .aMule/Incoming which I could not rename because tilde is reserved for home directory. I know I can access it via Nautilus by showing hidden files. How can I pull it out in terminal?

Update This is how it looks like now

   manuzhang@manuzhang-R458-R457:~/.aMule/Incoming$ ls -l
   total 328
   -rw-r--r-- 1 manuzhang manuzhang 297266 2012-03-19 12:07 ~
   -rw-r--r-- 1 manuzhang manuzhang  34479 2011-10-11 19:51 [kat.ph]friends.season.1.with.english.subtitles.torrent
share|improve this question

3 Answers 3

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.

The character ~ 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 ~. Run 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 foo and 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 ls.

share|improve this answer
1  
Note that usually only GNU tools understand -- to mean the end of options. –  Ignacio Vazquez-Abrams Apr 5 '12 at 0:50
1  
@IgnacioVazquez-Abrams Most commands do understand --: it's mandated by POSIX (apart from a few historical exceptions like echo), and it's provided by getopt, so pretty much any command that takes single-character options understands it. –  Gilles Apr 5 '12 at 0:54
1  
@manuzhang Are you sure that your file is called ~ (with an ASCII tilde)? Is it maybe called ` ̃ ` or some other visually similar character (which would explain how you created the file in the first place: in the command you show, a tilde should have been interpreted as the home directory)? –  Gilles Apr 5 '12 at 0:58
3  
@manuzhang This is not an ASCII tilde, but a U+FF5E FULLWIDTH TILDE, probably typed with a Chinese or Japanese input method. Either use the same input method, or copy-paste the character from the ls output. –  Gilles Apr 5 '12 at 1:13
1  
what a mistake!!! Sorry, I should've thought of it myself and saved your time. Anyway, thank you guys. –  manuzhang Apr 5 '12 at 1:16

Specify a path to the file.

cat ./~
share|improve this answer
    
cat: ./~: No such file or directory –  manuzhang Apr 5 '12 at 0:44

The pasted update shows it is some high-ASCII or Unicode character, not a simple tilde... Can you use mc or another file manager? How about move everything else out of that directory, then using tab completion?

share|improve this answer
1  
Since it's not actually a tilde the original problem ("~ is interpreted as the user's home directory") doesn't exist. Simple copy-and-paste (or typing it in using the same IM as when it was originally typed) will work. –  Ignacio Vazquez-Abrams Apr 5 '12 at 1:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.