Camilo Celis Guzman
Camilo Celis Guzman

Reputation: 615

How to delete ~ without deleting my home directory?

By mistake while using vim when exiting using :wq! I type an extra character (~) this created a directory named ~; however if I cd into it it would take me to the current user's home. How can I remove this directory without actually remove my home directory?

Upvotes: 3

Views: 675

Answers (3)

Denis
Denis

Reputation: 19

All of the recommended ways didn't help in my case. So I did:

rm -rf ./'~'

and it helped to get rid of "~" directory in my user dir.

Upvotes: 1

Camilo Celis Guzman
Camilo Celis Guzman

Reputation: 615

It can be solved using rm -rfi ./\~, which explicitly specifies the current directory.

(*) Similar question already ask here (thanks @AvihooMamka)

Upvotes: 3

Matthew Newton
Matthew Newton

Reputation: 655

Just quote the ~. Use rmdir, not rm, to be safe (rmdir will only remove an empty directory, so won't get rid of your home directory even if you mess it up).

$ mkdir '~'
$ ls -la '~'
total 16
drwxr-xr-x  2 me users  4096 Apr 20 13:20 .
drwxr-xr-x 97 me users 12288 Apr 20 13:20 ..
$ rmdir '~'
$ ls -la '~'
ls: cannot access ~: No such file or directory
$ 

Upvotes: 4

Related Questions