Accidentally created directory named "~" (tilde)
Escape the ~
with \~
or use single quotes '~'
.
so you can
rmdir ~/\~
or
cd ~ ; rmdir '~'
What python giveth, python taketh away:
$ python -c 'import os; os.makedirs("~/foo")'; tree; python -c 'import os; os.removedirs("~/foo")'; tree
.
└── ~
└── foo
2 directories, 0 files
.
0 directories, 0 files
If you did os.mkdir
, you could undo it with os.rmdir
(and similarly for os.makedirs
and os.removedirs
).
You can either escape the directory name using a backslash like this (assuming you're operating in the parent directory of the one you want to delete):
rmdir \~
Or you can use relative paths with a dot as the current directory (also when located in the parent directory):
rmdir ./~
Or you can use the full absolute path:
rmdir /home/USERNAME/~
And no worries, rmdir
can only remove empty directories. If you accidentally mistype the command and the path would evaluate to your real home directory, it is not in danger because it contains files:
$ rmdir directory_with_files
rmdir: failed to remove ‘directory_with_files’: Directory not empty