dan
dan

Reputation: 6314

Delete a folder named ~ in unix

Under my home directory I see a directory named ~. I guess I must have accidentally copied my home directory somehow.

Anyway, it's eaten up all my space and I'd like to remove it but obviously just running rm -r ~ will delete the entire contents of my home directory.

Any idea how to delete that ~ directory without any damage?

Upvotes: 0

Views: 129

Answers (4)

Dominique
Dominique

Reputation: 17501

You can try to make an ls | grep -v <other files> statement, which ignores all the other files, so that it only lists the file with that weird name.
Then you do:

rm $(ls | grep -v <other files>)

Obviously, you need to be careful first to test this thoroughly.

Upvotes: 1

Am Elemara
Am Elemara

Reputation: 11

I would use rm -rf \~ The \ escape key should stop you from deleting you're home directory.

Upvotes: 1

NRitH
NRitH

Reputation: 13893

Just add a \ before it: rm -rf \~.

Upvotes: 2

John Kugelman
John Kugelman

Reputation: 361730

Escape it so the shell doesn't expand the tilde. Any of these will do:

rm -r '~'
rm -r \~
rm -r ~/'~'
rm -r ~/\~

Upvotes: 1

Related Questions