Remix.run Logo
Twirrim 12 hours ago

I've biased towards this heavily in the last 8 or so years now.

I've yet to have anyone mistakenly modify anything when they need to pass --commit, when I've repeatedly had people repeatedly accidentally modify stuff because they forgot --dry-run.

IgorPartola 11 hours ago | parent | next [-]

I wouldn’t want most things to work this way:

    $ rm file.bin
    $ rm —-commit file.bin
    $ cat foo.txt > bar.txt
    $ cat foo.txt | tee —-write-for-real bar.txt
    $ cp balm.mp3 pow.mp3
    $ cp —-i-mean-it balm.mp3 pow.mp3
There is a time and a place for it but it should not be the majority of use cases.
Darfk 11 hours ago | parent | next [-]

Totally agree it shouldn't be for basic tools; but if I'm ever developing a script that performs any kind of logic before reaching out to a DB or vendor API and modifies 100k user records, creating a flag to just verify the sanity of the logic is a necessity.

Joker_vD 11 hours ago | parent | next [-]

    if [ -n "$DRY_RUN" ] ; then
        alias rm='echo rm'
        alias cp='echo cp'
    fi
Of course, output redirects will still overwrite the files, since the shell does it and IIRC this behaviour can't be changed.
digiown 11 hours ago | parent [-]

set -o noclobber

7 hours ago | parent [-]
[deleted]
james_marks 11 hours ago | parent | prev [-]

Yep. First thing I do for this kind thing is make a preview=true flag so I don’t accidentally run destructive actions.

digiown 11 hours ago | parent | prev | next [-]

For most of these local data manipulation type of commands, I'd rather just have them behave dangerously, and rely on filesystems snapshots to rollback when needed. With modern filesystems like zfs or btrfs, you can take a full snapshot every minute and keep it for a while to negate the damage done by almost all of these scripts. They double as a backup solution too.

ronjakoi 8 hours ago | parent | prev | next [-]

I used to have alias rm='rm -i' for a few years to be careful, but I took it out once I realised that I had just begun adding -f all the time

wonger_ 2 hours ago | parent [-]

See also rm -I (capital i), which only prompts when deleting directories or >3 files

hdjrudni 11 hours ago | parent | prev [-]

Even in those basic examples, it probably would be useful. `cp` to a blank file? No problem. `cp` over an existing file? Yeah, I want to be warned.

`rm` a single file? Fine. `rm /`? Maybe block that one.

Izkata 7 hours ago | parent [-]

That last one would error without doing anything anyway because it's not recursive.

__turbobrew__ 7 hours ago | parent | prev [-]

—dry-run should default to true

fainpul 2 hours ago | parent [-]

In PowerShell there's a setting for this:

https://learn.microsoft.com/en-us/powershell/module/microsof...