Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

Update

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

share|improve this question
add comment

8 Answers

up vote 8 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
add comment

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
1  
Then don't press TAB and use '' around the ~. –  Iain Nov 30 '11 at 10:36
add comment

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
add comment

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

rm ./~
share|improve this answer
add comment

Without pressing tab, try

rmdir \~
share|improve this answer
add comment

Giving the absolute path solved the problem.

rmdir /home/user/~

and TAB didn't rewrite it to something else.

share|improve this answer
add comment

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
add comment

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
add comment

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.