this post was submitted on 31 May 2025
959 points (99.1% liked)
Programmer Humor
23844 readers
2349 users here now
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
OK I'll bite, how do you get rid of a literal ~ directory?
rmdir ./~
Just give rm the entire path or a relative path like ./~
A method not yet mentioned is by inode, (I've accidentally created filenames I didn't know how to escape at the time like
--
or other command line flags/special characters)ls -li
Once you get the inode
find . -type f -inum $inode -delete
prefix with path, and/or quotation
Using Nautilus or Dolphin.
True if these are installed, but if I'm on a server's command line they probably aren't.
rm -rf "~" may work?
No, but single quotes will.
huh, I almost removed my entire home directory
In case you are just testing it out, don't use
-rf
Your
~
directory is most probably empty, so userm -d
instead, to prevent all footguns in case you put the wrong character in the end.I feel safe doing
rm -d /
.I feel safe doing
sudo rm -d /
.Because it won't delete anything that has a file in it.
I don't understand the eagerness of most people to go nuclear by adding potentially dangerous arguments when not required.
Use
rmdir
to remove a directory you expect to be empty, notrm -rf
It's because they know how to use rm -rf, and they don't know how to use rmdir. Honestly, I can't think of a single time I've ever successfully removed a directory with rmdir. I always wind up using something else.
In these touchy cases always add '-i' to have a confirmation when doing dangerous things. This will save your ass.
why
-exec rm
when find has a -delete flag?Is that some new-fangled GNU thing? It's certainly not POSIX.
Oh, for once the BSD version has more options than the GNU one.
Should be
\~
in most shells, certainly bash. Usemkdir
andrmdir
when messing around to prevent accidents.Saw this post this morning and was thinking about how to delete it ( while falling back asleep ). Escaping the ~, ofc that'd work! I feel so stupid now haha