News for hackers. Stuff that matters.
Re:I Accidentally Deleted 7TB of Videos Before Going to Prod... by maccard on Thursday May 05, 2022 @07:52AM (#31272147)
Deleting * may not be though. Your selection needs to be idempotent.
Re:I Accidentally Deleted 7TB of Videos Before Going to Prod... by maweki on Thursday May 05, 2022 @08:01AM (#31272234)
idempotency means that f(X) = f(f(X)). Modifying the X inbetween is not allowed. Is there really an initial environment where rm * ; rm * ; does something different than rm * once?
Re:I Accidentally Deleted 7TB of Videos Before Going to Prod... by einsty on Thursday May 05, 2022 @08:06AM (#31272275)
In the case of any live system, i would say yes. Additional, and different, files could have appeared on the file system in between the times of each rm *.
Re:I Accidentally Deleted 7TB of Videos Before Going to Prod... by mikeryan on Thursday May 05, 2022 @08:52AM (#31272706)
* is just short hand for a list of files. Calling rm with the same list of files will have the same results if you call it multiple times. That’s idempotent.

Your example is changing the list of files, or arguments to rm between runs. Same as pc85’s example where the timestamp argument changes.

Re:I Accidentally Deleted 7TB of Videos Before Going to Prod... by pc86 on Thursday May 05, 2022 @08:07AM (#31272292)
In addition to what einsty said (which is 100% accurate), if you're deleting aged records, on any system of sufficient size objects will become aged beyond your threshold between executions.
Re:I Accidentally Deleted 7TB of Videos Before Going to Prod... by jameshart on Thursday May 05, 2022 @08:56AM (#31272722)
Right. You can kind of consider the state of a filesystem on which you occasionally run rm * purges to be a system whose state is made up of ‘stuff in the filesystem’ and ‘timestamp the last purge was run’.

If you run rm * multiple times, the state of the system changes each time because that ‘timestamp’ ends up being different each time.

But if instead you run an rm on files older than a fixed timestamp, multiple times, the resulting filesystem is idempotent with respect to that operation, because the timestamp ends up set to the same value, and the filesystem in every case contains all the files added later than that timestamp.

Re:I Accidentally Deleted 7TB of Videos Before Going to Prod... by hansel_der on Thursday May 05, 2022 @09:59AM (#31273418)
> Is there really an initial environment where rm * ; rm * ; does something different than rm * once?

if * expands to the rm binary itself, maybe.

Re:I Accidentally Deleted 7TB of Videos Before Going to Prod... by maweki on Thursday May 05, 2022 @10:45AM (#31274028)
How is the system different after the first and after the second call?
Re:I Accidentally Deleted 7TB of Videos Before Going to Prod... by jgoldshlag on Thursday May 05, 2022 @10:53AM (#31274140)
If there is an rm executable in the current directory, and also one later in your PATH, the second run might use a different rm that could do whatever it wants to
Re:I Accidentally Deleted 7TB of Videos Before Going to Prod... by dotancohen on Friday May 06, 2022 @03:35AM (#31282397)
This is actually a likely scenario, as it is common to alias rm to rm -i. Though your bash config will still run after .bashrc is nuked, some might wrap with a script instead of aliasing (e.g., to send items to Trash).
Re:I Accidentally Deleted 7TB of Videos Before Going to Prod... by hansel_der on Friday May 06, 2022 @05:53AM (#31283318)
# rm rm

# rm rm

rm: command not found