Hacker News new | ask | show | jobs
by jmholla 453 days ago
> because for write-protected files '-i' is a no-op.

On my machine, `rm -i` with a yes to a read-only file does delete that file. But maybe I'm misunderstanding what you mean by it being a no-op.

    > touch foo
    > chmod 400 foo
    > ls -l
    total 0
    -r-------- 1 joshua joshua 0 Mar 26 00:06 foo
    > rm -i foo
    rm: remove write-protected regular empty file 'foo'? y
    > ls -l
    total 0
> but there is another problem i have with using an alias, this may not apply to you, but i work on multiple machines and in containers, and i keep creating new ones for projects, that there is a high risk that i forget to set the alias. so every time i use rm i can't be sure, did i set the alias, or did i not. and if i rely on 'rm' always asking me, then it makes me complacent. ah, i don't have to pay attention because rm will ask me anyways.

Oh yea. I've definitely run into this. Luckily, a large percentage of my stuff off my dev machine is backed by code, so I can usually just throw things away and bring them all the way back up.

> writing 'rm -i' explicitly every time makes it much easier to see that '-i' is indeed being invoked. it makes me pay attention and i know that i am running the command that i want. it's three extra characters to type each time, but it has become muscle memory. i don't think about it anymore, except when verifying what i typed. the '-i' just has to be there.

Ha. I know that feeling, and this is probably something I should've let happen to me with these dangerous commands. Would definitely make my experience with cp a lot better. I have so many aliases I've made to make my life easier, but I just end up typing in the full command every time. :D

1 comments

`rm -i` with a yes to a read-only file does delete that file. But maybe I'm misunderstanding what you mean by it being a no-op.

'rm' (without '-i') does exactly the same. so for read-only files, '-i' changes nothing.

whereas '-f' does change the behavior of 'rm' on read-only files. it doesn't just override '-i'.

Ah. I totally see what you meant now. Thank you for clarifying!

I had thought you mean that `rm -i` would do nothing to read-only files. Not that the flag itself was a no-op.