32

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.

Kees Cook
  • 17,823
theTuxRacer
  • 16,533

5 Answers5

60

rm -R ./~

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

44

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'?
    
Oli
  • 299,380
19

Brilliant problem :)

You can delete the directory by escaping the tilde:

rm -rf \~

This works for all sorts of special characters.

17

You can simply cake the folder name into apostrophes:

 rm '~'
Yuriy Voziy
  • 1,105
6

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.
superfav
  • 161