Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This is the output of ls -l

ls -l
total 53484
drwxr-xr-x 3 root root     4096 2011-02-10 05:59 ~
-rw-r--r-- 1 root root 54313810 2011-02-13 05:09 jobs.jar
-rw-r--r-- 1 root root   384035 2011-02-15 05:33 jobsLog.out

I can't do rm -rf ~ because that will remove my home directory.

What should I do? Its not a problem for me, but just an eye-sore.

share|improve this question
8  
I'd avoid writing rm -rf on something with such potential for failure if you mis-type. Consider entering your ./~ folder and removing its contents from there before moving up a directory and running rmdir ./~ to remove the ~ directory itself. –  adamnfish Feb 15 '11 at 10:52
add comment

5 Answers 5

up vote 42 down vote accepted

rm -R ./~

That will make it look for ~ in the current folder.

share|improve this answer
    
wow, way to look at things straight! kudos! –  theTuxRacer Feb 15 '11 at 11:29
    
This answer is correct, but I think Oli's answer is better because it is safer. If you slightly mistype this command, you will permanently trash your system. –  HDave Apr 2 '13 at 13:00
add comment

I've made silly mistakes with rm before so here are a few tips I've learnt over the years to try and keep you data safe from accidents:

  1. Use a graphical solution like Nautilus. Soft-delete it to the trash. Then when you know you haven't moved your $HOME into the trash (everything would have started crashing and looking funky), empty your trash.

  2. Move instead of delete. Rename the directory with mv, eg:

    mv ./\~ ./a-nice-sensible-directory-name
    

    Then delete it.

  3. If in doubt, use the -i flag when dealing with potential fubars. It will prompt you for every file removed and should let you very quickly know if something bad is going to happen.

    oli@bert:~/Desktop$ rm -rfi ./del/
    rm: descend into directory `./del'? y
    rm: remove regular file `./del/output2.pdf'?
    
share|improve this answer
1  
cant GUI, its a ssh terminal :P Good idea about the mv. I think I should make the rm alias with a rm -i. –  theTuxRacer Feb 15 '11 at 11:28
5  
You can bung ssh://user@ip/folder into nautilus. Doesn't work for everything (eg if you need to sudo), but there you go. Aliasing -i is a double-edged sword. It's helpful but it's also vastly irritating when you do lots of files. Consider -I too. And look at man rm for more tips. –  Oli Feb 15 '11 at 11:32
    
+1 for the move idea. Now I wonder why there isn't a drop-in replacement for rm that moves to (say) ~/.Trash. –  ShreevatsaR Feb 16 '11 at 5:27
add comment

Brilliant problem :)

You can delete the directory by escaping the tilde:

rm -rf \~

This works for all sorts of special characters.

share|improve this answer
add comment

You can simply cake the folder name into apostrophes:

 rm '~'
share|improve this answer
add comment

Just another, a little more complex, way to do it is using inode numbers:

$ ls -li
total 24
 7146369 drwxr-xr-x   4 user  staff   136 Jan 19 21:50 ~
$ find . -xdev -inum 7146369 -exec rm -rf {} \;

Pros

  • It works with wathever fancy name you can have.
  • Should be safe because inode numbers are unique (-xdev: Don't descend directories on other filesystems) and you can test the search first, just in case, removing -exec rm -rf {} \;.

Cons

  • Doing find . in a directory with a lot of files and/or directories will take a lot of time, and disk reading.
share|improve this answer
    
I was always interested in inodes, and was wondering whether it was possible to do it =) –  theTuxRacer Feb 16 '11 at 5:33
    
Of course, this only works if your current filesystem has the concept of an inode (not all the filesystems Ubuntu supports have this concept -- though most of those that do not are not native Unix filesystems like vFat and NTFS) –  Billy ONeal Feb 16 '11 at 16:19
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.