by ptman · 8y ago · 0 comments
r
rm
rm -
rm -rf
rm -rf ~
rm -rf ~/
rm -rf ~/tmp
# where did my files go?That said, I'm starting to think — should I include a note about the potential dangers in the readme?... they seemed glaringly obvious to me (at least in case of rm-like commands), but can there be readers/users, to whom they'd not be obvious?...
edit: Ok, I tried to add a warning in the Readme, that's something I can do easily, and if it helps someone, worth it...
But if there is a way for you to drop the capability to modify the filesystem before running the first pipeline, you should definitely do it by default (and provide a switch to override it if somebody knows what they are doing.)
Even rm has a -f flag to override some safety measures, though the defaults aren't very safe.
Could you have this command run as user “nobody” by default, and have a flag to run as a real user? Or as others have mentioned, use capabilities on the spawned processes to prevent anything other than standard input/output?
Strukt doesn't do 'rm' yet (and nobody has ever requested it), but it does have other operations that do writeback. Once you add one, automatic updates are disabled, and you have to explicitly run the pipeline each time you want it run.
We really need a new cross-platform low-level framework for lego-like operations, like shell commands but updated for the 21st century.
WhatIf instructs the command not to make any changes, but merely to log what it would do. You can "Remove-Item C:\Windows -Force -WhatIf" and it will output "What if: Performing the operation "Remove Directory" on target "C:\windows"" but not delete anything.
(implementing support for "whatif" is optional, so you can't casually use it on any given cmdlet without first checking that cmdlet supports it and makes sensible use of the parameter instead of ignoring it, but the idea is there).
(That's the common Unix shell name for it, though it's not entirely consistent -- which is another problem with using Unix built-ins!)
One thing I've noticed is that it's really frustrating (and not at all helpful) to require perfect validity from a shell-like tool. There's just too many times where you want to edit something into something else, without needing to find a perfect path of valid and meaningful syntax at every intermediate step. So if you have a flag on an operation that doesn't understand that flag, the flag will have a (?) badge to indicate that it won't be understood or used, but the pipeline will still run.
Meant to type:
rm -rf node_modules && npm install
Question: what's immediately next to the & key on a keyboard?Answer: *
Actually typed
rm -rf node_modules ** npm install
Oops.Theory is: rm is dangerous and should not be used day to day.
It's always been surprising to me that their isn't a built in "undo" to `rm`
e.g. why doesn't `rm` just move files to /tmp?
The default rm doesn't do this because shell users are supposed to be able to figure out how not to delete things they want to keep.
Kind of like not pointing a gun at people who you don't want to kill.
The undo for rm is regular backups.
On my system I have snapshots of my home directory created every 15 minutes. Not quite the same thing, but it also helps me when I have incorrectly modified a file.
And do what when tmp gets full and services & applications start crashing?
When someone implements that undo, someone's going to need to write a tool that really does remove files, really. Will the next guy wonder why really-rm doesn't have undo built in?
Same question as parent: "And do what when tmp gets full and services & applications start crashing?"
We could all just work with WORM drives instead.
Have a look at either the `trash-cli` package by Andrea Francia.
I don't do this because my idiocy must be punished disproportionately. Also, you end up automatically pressing y enter.
Aliases can be way more dangerous; think about what you're doing. This is what backups are for.
I don't think I'd ever want to use this tool. Every keystroke could be an arbitrary command, and I wonder about the performance of commands with a lot of I/O or processing.
Conceptually it's really neat and I get it, but practically I find things like parameter completion in Fish much more useful.