Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A defect program have created a directory called ~.

If I do rm \~ and then TAB it translates to ~/ which is the users home directory.

How do delete such a directory?


See my answer that solved the problem. It is based on the posted answers.

share|improve this question
up vote 9 down vote accepted
rmdir ./~

So, basically, you're specifying the path in such a way that there won't be shell expansion on the "~".

share|improve this answer

Use rmdir '~' which should do the trick.

share|improve this answer
I tried that, and TAB rewrote it to ~/ – Sandra Nov 30 '11 at 9:51
If you type what I wrote WITHOUT the TAB then it works. If you type what I wrote and hit TAB then it expands to '~'/ which works. Why are you bothering with tab in this situation? What is your fascination with TAB? – Iain Nov 30 '11 at 9:56
Because I want to make sure that the users home directory isn't deleted. – Sandra Nov 30 '11 at 10:16
Then don't press TAB and use '' around the ~. – Iain Nov 30 '11 at 10:36

As a general answer for any file.

ls -i

take that number and bung it in find -maxdepth 1 -inum [number] -exec rm -r {} \;

share|improve this answer

I have confirmed the following works. You can use tab completion on this as well.

rm ./~
share|improve this answer

Without pressing tab, try

rmdir \~
share|improve this answer

Giving the absolute path solved the problem.

rmdir /home/user/~

and TAB didn't rewrite it to something else.

share|improve this answer

The shell performs wildcard expansion on several reserved symbols, the tilde being one example. When the shell sees

$ rm ~

It expands the tilde to the path of the user's home directory. Essentially, the shell 'sees' this, instead:

$ rm /home/$USER/

To prevent wildcard expansion, escape the symbol with a \, like so:

$ rm \~

This will ensure that the shell deals with the ~ literally.

You have two options for deleting a directory called ~:

For a non-empty directory, pass the recursive flag to rm:

$ rm -r \~

And for an empty directory:

$ rmdir \~
share|improve this answer

first thought would be "dont use tab" , but untested. Better option: install "mc" (midnight commander) and delete the directory from its interface. its a bit of a workaround though.

share|improve this answer

Your Answer


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.