• @ladicius
    link
    English
    234 days ago

    Save a copy anywhere, get rights, overwrite original file with new file.

    At least try that.

    • @Droggelbecher
      link
      English
      74 days ago

      Nice of you to try to help, but I don’t think the people who post in this community are open to learning

      • madthumbsOPM
        link
        English
        -74 days ago

        The community is not for Linux vs Windows or to humor Linux users. It is for dumping on Linux and it’s evangelists. I’m not going to let evangelists take over and trash it. This simple solution isn’t blaming the user (common evangelist BS), it isn’t making a false claim of Linux being ‘better’ for it. -So I see no harm in it and updooted it myself.

    • @iks
      link
      English
      33 days ago

      Save in /tmp

      • @[email protected]
        link
        fedilink
        English
        17 hours ago

        Actually if you open a file you only have read access to in Windows, it will be exactly the same.
        Save it to your desktop, get rights, copy it to its original location.

    • madthumbsOPM
      link
      English
      -24 days ago

      Easiest to rember trick I know of, but most people aren’t going to know it the first time they’re hit with it. lol

  • @billbasher
    link
    English
    163 days ago

    :w !sudo tee %

    If you are in vim you can do this

      • @billbasher
        link
        English
        23 days ago

        It looks like you can run shell commands so it should be possible although the syntax may be a bit different. I haven’t used Helix.

  • Shadow
    link
    fedilink
    English
    104 days ago

    Same shit happens with notepad in windows when editing the hosts file.

    • @[email protected]
      link
      fedilink
      English
      23 days ago

      Notepad++ handles this gracefully

      It offers to relaunch itself elevated without losing what you just edited.

    • madthumbsOPM
      link
      English
      -1
      edit-2
      4 days ago

      You’re right, some AI chat told me it wouldn’t even open (by default). But at least it has a decent suggested solution in the error.

      • @[email protected]
        link
        fedilink
        English
        13 days ago

        It’s so stupid that it can’t bring open an UAC prompt instead. Come on Windows you have a standardized way to elevate! Why don’t you use it?

      • @theunknownmuncher
        link
        English
        14 days ago

        Kudos for being willing to try it and see!

        One very minor detail to note, in your test you weren’t actually overwriting the original file that you opened, but instead Notepad appended a .txt to the filename, which is its default behavior, but you still got the same type or error because you didn’t have write permission for any file in that directory.

  • @Clent
    link
    English
    74 days ago
    :w !sudo tee %
    

    Further research because you wouldn’t use sudo for something you don’t understand, right?

    Right?!?

  • @[email protected]
    link
    fedilink
    English
    33 days ago

    This is why i love micro. When you tell it to save without sudo it asks to elevate your privileges.

  • Ephera
    link
    fedilink
    English
    54 days ago

    Modern versions of Vim warn about this. I guess, this might still be an annoyance with other editors?

    • madthumbsOPM
      link
      English
      -74 days ago

      If I recall it was when you opened it, and it was easily overlooked.

  • Baggins [he/him]
    link
    fedilink
    English
    14 days ago

    I saw a one liner somewhere that lets you privesc the vi process you’re running from the vi command prompt

  • AwkwardLookMonkeyPuppet
    link
    English
    03 days ago

    If you open it in code instead of vim or nano, then you can escalate the privileges if needed. It’s also easier to work with overall.

  • @theunknownmuncher
    link
    English
    04 days ago

    The bike meme is accurate in that it is you who did it to yourself

      • @theunknownmuncher
        link
        English
        -24 days ago

        Based on the community, I figured it was trying to imply that this is somehow Linux’s fault

    • madthumbsOPM
      link
      English
      -74 days ago

      “ItS nOt LiNuX fAuLt!” - Common trope for the cult.

      Thanks for the good example of how the cult blames the victim.

      • @theunknownmuncher
        link
        English
        3
        edit-2
        3 days ago

        That very well may be a toxic trope in the Linux community, but in this specific case, I’d say it actually is the user’s fault.

        Since you believe it is the operating system’s fault, I am curious how would you like the operating system to behave differently than this, when a user interacts with a file that they have read permissions but not write permissions? What should it do? The cool thing about Linux is that if you have a better idea, you are free to implement it and make it reality, and maybe even contribute it so that others can benefit too

        Personally, I feel this behavior is already the best way to go, and why it works this way in all operating systems (at least that I am aware of). I understand that it makes it easy for the user to make this mistake, but I think it would be wrong to block the user from reading a file that they have permissions to read, obviously it would be wrong to allow them to write when they do not have permission, and at least (on Linux) they are given the option to save their changes to an alternative location that they have write permissions for, and warned when opening a readonly file for editing. Is there a better way?

        • madthumbsOPM
          link
          English
          -33 days ago

          What should it do?

          Suggest a practical solution like saving to another directory where it can later be moved. (Notepad in Windows will do this)

          • @theunknownmuncher
            link
            English
            2
            edit-2
            3 days ago

            That is a neat idea. You can implement this change in vim (or the editor of your choice), and open a pull request to contribute it if you wish! Another idea would be for the editor to automatically re-open itself with escalated privileges, maybe caching your changes to a temporary file so that you do not lose anything (could be dangerous if editing sensitive data that shouldn’t be written to a temporary location, or if you didn’t understand that you were opening a system file that you should be cautious in [but I can think of ways to mitigate that problem, too! Like just notifying the user that the editor needs to escalate the privilege]). I think it is important to realize that none of these solutions are the responsibility of the operating system itself, but instead the programs that you are choosing to use (Notepad/vim)

            Modern versions of vim do warn the user up-front when they open a readonly file for editing, which I think is a nice solution, but sure, it doesn’t explicitly offer to save the file in your home directory for you. This is still always an option though (:w ~/myfile), and if you don’t know how to use your text editor to save a file and need that level of hand-holding, then maybe you shouldn’t have sudo access in the first place?

            • madthumbsOPM
              link
              English
              -33 days ago

              TBH, I rarely noticed the warning from nvim. I did get in the habit of learning when to use sudoedit though.

              • @theunknownmuncher
                link
                English
                2
                edit-2
                3 days ago

                Sometimes I overlook the warning too, to be completely honest. But when that happens, I think “oh, my bad” and not “this is Linux’s fault!”

                I’m sure that you can restyle the warning in vim so that it is more eye catching, but I’ve never tried.

                • madthumbsOPM
                  link
                  English
                  -23 days ago

                  We can’t very well honestly call Linux ‘new user friendly’ with issues like this that many of us are familiar with. Another legit attitude to have is: “what do you expect for free?”.

      • @theunknownmuncher
        link
        English
        14 days ago

        On which operating system can you write to a file that you do not have permissions to write to?

        This exact same behavior also occurs on Windows lol

        • madthumbsOPM
          link
          English
          -44 days ago

          By default, a text editor in Windows will not even open the file for you to edit if you do not have the privilege already.

          • @theunknownmuncher
            link
            English
            4
            edit-2
            4 days ago

            This is simply not true. Try it. I just did! File opens in notepad but when you save, you get an error. It does allow you to open the file without write permission because you have the option of saving it to a location where you do have permissions. Just like Linux 🙂

            • madthumbsOPM
              link
              English
              -13 days ago

              Ok, checked it and you’re right, contrary to what I read. It does suggest in the error on Windows to save it to your documents instead at least.