5 ms·
If we're going to criticise Unix file naming, I'd rather talk about how file names with spaces in them break things, or how hard it is do delete a file named "-
by TorKlingberg 9y ago
If we're going to criticise Unix file naming, I'd rather talk about how file names with spaces in them break things, or how hard it is do delete a file named "-".
- zanchey 9y agoThere's something in my environment that keeps creating a file called "-" in my home directory, and it's driving me crazy.
- jovial_cavalier 9y agoBy convention, when a unix program is passed "--" it means there are no more flags being passed. Try the following: $ rm -- -
- ConfucianNardin 9y agoThis will not work with all rm implementations, in which case you can fall back to: rm ./-
- zanchey 9y agoOh, I can remove it... And a few hours or days later it's back!
- jovial_cavalier 9y agoOkay, you're gonna want to type $sudo crontab -e...
- codedokode 9y agoIt is better to write EDITOR=nano sudo crontab ... otherwise instead of edititng the crontab you will be solving the problem of exiting vi.
- zanchey 9y agoAll the interest encouraged me to dig in and find it, and it turned out to be in one of zsh's many startup scripts.
- jsymolon 9y agolist the file showing inode number, rm by that particular inode.
- RHSeeger 9y agoOpen the parent directory with emacs and you can use it to delete the rogue directory/file. Admittedly, there's easier ways for a "-" named file, but its a good solution to know since you can use it to delete even the most difficult filenames.
- exprA 9y ago>I'd rather talk about how file names with spaces in them break things Not really a Unix thing, but some tools (rather common even) are indeed very broken when it comes to certain types of file names. However... >how hard it is do delete a file named "-" While it's certainly a corner case of sorts, if you call that task hard, I wonder how you fare with using more complex software, like a web browser...
- ComputerGuru 9y ago> I wonder how you fare with using more complex software, like a web browser... That snark isn’t necessary. It’s easier to use a web browser than to delete a file called - from the terminal. Or haven’t you used a non-GUI system before?
- exprA 9y agoI don't agree with that at all; a web browser has easily a more complex user interface than a single-purpose command-line tool like “rm” – and that is even before we open any document at all, with all their conventions we have to learn before we can effectively navigate them. Everything has a learning curve, of course, but are you sure you're just not much more familiar with one of these two? (edit: just to clarify, what do you expect a decent rm to do when given a single argument of “-”? While there may still be systems where that does not do what you'd expect it to do – it's no different to existing obsolete versions of browsers that do nothing at all when you type in something other than a valid URL in the address bar – and are thus considerably harder to use for some not familiar with the technology. The harder corner case would be to try and remove a file with name that can be confused for a valid flag – like '-i' – but even then, that's about the only corner case for the tool, and not a steep step to learn. Any recent coreutils rm will even suggest a valid command to remove files that look like options, but are not actually valid options, so some thought has been given to discoverability as well.)
- jlgaddis 9y agorm -- -
- YSFEJ4SWJUVU6 9y agoWhile GNU's not unix... afaik GNU coreutils' rm has done exactly what you expect it to when given a single dash as an argument for who knows how long. The problem is names that could be interpreted like options, like '-f' or '--help'.
- mort96 9y agoInterestingly, when the shell expands * , it won't do anything to make sure files starting with - are handled properly. This means, if you're in a directory with the files a, b, -rf, and the directories foo/ and bar/, running "rm * " will not delete all the files and keep all the directories; instead it will be turned into "rm a b bar foo -rf", meaning it will delete all the files and directories except for the file -rf.
- xelxebar 9y agoI've definitely run into this on bash and zsh (iirc). I'm curious if this glob expansion behaviour is set in posix somewhere.
- deleted 9y ago[deleted]