this post was submitted on 24 Mar 2024
366 points (100.0% liked)

linuxmemes

24355 readers
320 users here now

Hint: :q!


Sister communities:


Community rules (click to expand)

1. Follow the site-wide rules

2. Be civil
  • Understand the difference between a joke and an insult.
  • Do not harrass or attack users for any reason. This includes using blanket terms, like "every user of thing".
  • Don't get baited into back-and-forth insults. We are not animals.
  • Leave remarks of "peasantry" to the PCMR community. If you dislike an OS/service/application, attack the thing you dislike, not the individuals who use it. Some people may not have a choice.
  • Bigotry will not be tolerated.
  • 3. Post Linux-related content
  • Including Unix and BSD.
  • Non-Linux content is acceptable as long as it makes a reference to Linux. For example, the poorly made mockery of sudo in Windows.
  • No porn, no politics, no trolling or ragebaiting.
  • 4. No recent reposts
  • Everybody uses Arch btw, can't quit Vim, <loves/tolerates/hates> systemd, and wants to interject for a moment. You can stop now.
  • 5. πŸ‡¬πŸ‡§ Language/язык/Sprache
  • This is primarily an English-speaking community. πŸ‡¬πŸ‡§πŸ‡¦πŸ‡ΊπŸ‡ΊπŸ‡Έ
  • Comments written in other languages are allowed.
  • The substance of a post should be comprehensible for people who only speak English.
  • Titles and post bodies written in other languages will be allowed, but only as long as the above rule is observed.
  • 6. (NEW!) Regarding public figuresWe all have our opinions, and certain public figures can be divisive. Keep in mind that this is a community for memes and light-hearted fun, not for airing grievances or leveling accusations.
  • Keep discussions polite and free of disparagement.
  • We are never in possession of all of the facts. Defamatory comments will not be tolerated.
  • Discussions that get too heated will be locked and offending comments removed.
  •  

    Please report posts and comments that break these rules!


    Important: never execute code or follow advice that you don't understand or can't verify, especially here. The word of the day is credibility. This is a meme community -- even the most helpful comments might just be shitposts that can damage your system. Be aware, be smart, don't remove France.

    founded 2 years ago
    MODERATORS
     
    all 39 comments
    sorted by: hot top controversial new old
    [–] kmirl@lemmy.world 50 points 1 year ago (2 children)
    fuck() {
        sudo $(fc -ln -1)
    } 
    

    This function takes the last command and puts sudo in front of it. Actually used it in a zoom call at work without thinking and it took a second to realize why everyone was laughing. Not my invention--came across it years ago on stackoverflow or someplace and thought it was funny/useful.

    kmirl@tux:~$ ls /root
    ls: cannot open directory '/root': Permission denied
    kmirl@tux:~$ fuck
    [sudo] password for kmirl: 
    bin  debs  docs  Mail 
    
    [–] folkrav@lemmy.ca 29 points 1 year ago

    Considering the function name, here’s an obligatory thefuck plug

    [–] Rustmilian@lemmy.world 15 points 1 year ago* (last edited 1 year ago)
    alias fuck='sudo $(fc -ln -1)'
    
    [–] huginn@feddit.it 28 points 1 year ago (2 children)

    Lazy vim way I do it:

    ggVG"wY:q! followed by sudo !! then VG"wp:x

    Grab entire file and stuff it in register W

    Exit file

    Reopen sudo

    Select all and replace with register W them write

    [–] rtxn@lemmy.world 28 points 1 year ago (1 children)

    Now I understand how the Adeptus Mechanicus feel when they perform a ritual power-on.

    [–] huginn@feddit.it 10 points 1 year ago

    It's funny how years of use make that so intuitive but spelled out it's a garbled mess

    [–] dukk@programming.dev 10 points 1 year ago (1 children)

    Lazier way:

    :w !sudo tee %

    [–] huginn@feddit.it 2 points 1 year ago

    Yeah learning about tee from this thread honestly.

    It's been interesting realizing I had such a useful tool at my disposal but never knew

    [–] bjoern_tantau@swg-empire.de 15 points 1 year ago (8 children)

    Is there an editor that can request root privileges without restarting it? That would be quite useful.

    [–] h3rm17@sh.itjust.works 11 points 1 year ago (1 children)

    In vim, in normal mode you can do: :w !sudo tee %

    [–] z3rOR0ne@lemmy.ml 3 points 1 year ago (1 children)

    Apparently that doesn't work in NeoVim, so recently I installed the suda plugin.

    Personally, I just doas nvim and then the file name that needs root access, but it's a handy plugin in case I forget.

    ??? I used this in neovim twice today

    :w !sudo tee % then reload when it asks.

    [–] Vilian@lemmy.ca 9 points 1 year ago

    i use micro

    [–] Botzo@lemmy.world 5 points 1 year ago

    It's a simple trick in Vim:

    https://stackoverflow.com/a/7078429

    For the lazy: :w !sudo tee > /dev/null %

    [–] eager_eagle@lemmy.world 4 points 1 year ago* (last edited 1 year ago)

    micro ftw, no need to even memorize a command, it'll just ask if you want to use sudo

    [–] hex_m_hell@slrpnk.net 4 points 1 year ago* (last edited 1 year ago)

    Yeah, in emacs you use tramp to open the file with /sudo::

    [–] chtk@feddit.nl 4 points 1 year ago
    [–] YodaDaCoda@sh.itjust.works 4 points 1 year ago

    kate does this in KDE, but it's not cli.

    [–] MonkderZweite@feddit.ch 11 points 1 year ago (1 children)

    Kwrite/Kate asks you for password. Seriously, why can't they all just use pkexec or some abstraction of it?

    Sadly, i currently borked all Qt apps on my Gtk setup.

    [–] caseyweederman@lemmy.ca 2 points 1 year ago (1 children)

    So does Micro. Nano... Nano does not.

    [–] MonkderZweite@feddit.ch 2 points 1 year ago

    Eh, on console i can just do ssu nano <file>. Graphical editors are in question.

    [–] stardreamer@lemmy.blahaj.zone 11 points 1 year ago (2 children)
    :w !sudo tee %
    

    Warning: does not work for neovim

    [–] dream_weasel@sh.itjust.works 1 points 1 year ago (1 children)

    sure it works in neovim

    I didn't do any editing since it's just to prove a point, but I think it does fine.

    [–] PipedLinkBot@feddit.rocks 1 points 1 year ago

    Here is an alternative Piped link(s):

    sure it works in neovim

    Piped is a privacy-respecting open-source alternative frontend to YouTube.

    I'm open-source; check me out at GitHub.

    One of the many reasons why I use micro

    [–] hex_m_hell@slrpnk.net 5 points 1 year ago (1 children)

    C-x C-f /sudo::/path/to/file

    [–] jxk@sh.itjust.works 3 points 1 year ago

    I love Emacs. Thanks for teaching me someyhing today

    [–] SexualPolytope@lemmy.sdf.org 4 points 1 year ago* (last edited 1 year ago)

    Use suda.vim for automatically dealing with such cases. Works with neovim as well.

    I'll also recommend adding the following to your init.lua or some config file because suda doesn't play nicely with nvim -d or vimdiff.

    -- Disable Suda in diff views
    if not vim.api.nvim_win_get_option(0, 'diff') then
        vim.g.suda_smart_edit = 1
    end
    

    The vimscript version of the same would be:

    " Disable Suda in diff views
    if ! &diff
        let g:suda_smart_edit = 1
    endif
    
    [–] Hoimo@ani.social 4 points 1 year ago* (last edited 1 year ago) (1 children)

    I am here for one reason and one reason alone: source anime is Watamote, episode 12 @18:36

    Tomoko tries to approach a girl, but the wind confuses her and she runs away in embarrassment, even though the girl was really friendly and would have liked to talk to her.

    In the meme, this scene is used to parallel the feeling of an external system blocking an operation that both participants would agree to.

    A similar feeling could be memed with the "myth of consensual sex" format.

    [–] Pantherina@feddit.de 4 points 1 year ago

    sudoedit is more secure btw. Many editors are not built to be ran as root, and this copies the file to a temo directory, edits it without root, and then overwrites the original file on save with root.