8 ms·
Generally, a destructive shell command prompts for approval. But I suppose overfumbly fingers could still cause grief. Type/command aware tooling is a night an
by owlstuffing 3y ago
Generally, a destructive shell command prompts for approval. But I suppose overfumbly fingers could still cause grief.
Type/command aware tooling is a night and day difference.
- mksybr 3y agoGenerally? Do you have examples in mind? The ones I think of are destroy first and ask questions only if told to do so: mv cp rm redirection tee
- owlstuffing 3y agoYeah, you’re right. I was thinking of overly destructive commands eg. reformat etc.
- tombert 3y agoI feel like I've trashed millions of files I shouldn't have with `rm` and trying to be clever with regular expressions.
- doubled112 3y agoI've done this enough times I use `ls` first, then `rm`
- tombert 3y agoYeah, I generally will use `find . -name "<my pattern"` nowadays, just so I can see all the potentially recursive files as well, and then when I'm 100% sure that what I'm doing is good, I will pipe that into xargs or parallel. My point was that I don't feel like Unix really stops you from doing destructive scary stuff. It seems like it's perfectly happy to let you break your machine.
- doubled112 3y agoExactly, which is why we check for ourselves instead of expecting it to hold our hand. Unixy tools tend do what you tell them, nothing more and nothing less. No confirmations, no output if successful, no progress bars, etc. That's a feature in my mind, but I can see how it is easy to have your day ruined if you're expecting it to ask you again.
- tombert 3y agoI mostly agree, but sometimes I wish that `rm` would have default to "confirm before destroying", and add a flag like `-y` to not prompt, more or less like how `apt` works on Ubuntu.
- doubled112 3y agoThat's actually a way better experience than no confirmation and confirming each item individually.
- LtWorf 3y agorm can do that... set an alias to ask to confirm every time.
- tombert 3y agoThat's fine on my computer, but if I'm logging into a server I'm not going to do that every time.
- neuromanser 3y agoAs much as we all wish it wouldn't be so, TANSTAAFL. What is your suggestion and how does it maintain compatibility with the existing body of code?
- doubled112 3y agorm doesn’t provide an action summary, does it? Last time I used the interactive option, it needed me to press Y once for every file. If you have a list of 200 files you’re probably not even reading by the end.
- mananaysiempre 3y agoOr just add ‘echo’ in front: echo rm ... . Especially when the command is in a loop of some sort.
- reddit_clone 3y agoAs much as I can, I do a 'mv ... /tmp' instead of 'rm -rf'. It gets the files out of the way, and provides a way out if that's not what I wanted. '/tmp' will eventually be cleaned by the OS so no (prolonged) space worries.
- floppydisc 3y agoTo add to this, I've been a happy user of the trash-cli for forever. Can recommend.
- KMnO4 3y ago/tmp is a RAM disk on many systems so be careful with very large files
- insanejudge 3y agokind of the same deal with spooky SQL queries and verifying your where clause with a select first
- tombert 3y agoAt least with SQL you can just consistently wrap stuff in transactions, so if you break something you can always revert.
- rixed 3y agoalias rm='rm -i'
- AnyTimeTraveler 3y agoI set up hourly borg backups instead. That resulted in me aliasing rm='rm -rf' without a worry in the world. So far, I made about ten recoveries and have never lost important data.
- oefrha 3y agoIf you never rm’ed work you just did not captured by hourly backups, well, lucky you.
- teddyh 3y agoNote: Normal shells use glob(7) expressions, not regular expressions.
- tombert 3y agoYou know I googled this immediately after I posted it, and you're absolutely right, but a good chunk of the syntax still kind of looks like regular expressions so I don't think I was too far off!
- teddyh 3y agoRegular expressions and glob(7) expressions look superficially similar, but it is mostly an illusion; they both use * and ? as common metacharacters, but both of those characters mean different things in the two systems. Only the [ and ] characters are used more similarly, but even those have their differences. The two syntaxes only have one common function which functions identically in the two systems, but it is invoked by different characters; specifically the ? (question mark) character in glob(7) exactly corresponds to the . (full stop) character in regular expressions.
- Per_Bothner 3y agoTo be pedantic: You're conflating the syntax of regular exprssions, with the (computer science) concept. Glob patterns are a kind of very resticted regular pexressions. Ksh extended the glob syntax so it has the full power of regular expressions in the computer science sense - though without all the extensions of modern regular expressions.
- teddyh 3y agoNo, globs are not regular expressions. “Globs do not include syntax for the Kleene star which allows multiple repetitions of the preceding part of the expression; thus they are not considered regular expressions, which can describe the full set of regular languages over any given finite alphabet.” — <https://en.wikipedia.org/w/index.php?title=Glob_(programming)&oldid=1177361783#Compared_to_regular_expressions https://en.wikipedia.org/w/index.php?title=Glob_(programming...>