• papertowels
    arrow-up
    71
    arrow-down
    0
    ·
    25 days ago
    link
    fedilink

    sudo !! to rerun last command as sudo.

    history can be paired with !5 to run the fifth command listed in history.

    • communism
      arrow-up
      6
      arrow-down
      0
      ·
      25 days ago
      link
      fedilink

      Fifth as in fifth most recent command or fifth oldest?

      • papertowels
        arrow-up
        8
        arrow-down
        0
        ·
        25 days ago
        edit-2
        25 days ago
        link
        fedilink

        I believe it’s the fifth oldest - I think !-5 will get you the fifth impost recent, but I was shown that and haven’t put it into practice.

        The most common usecase I do is something like history | grep docker to find docker commands I’ve ran, then use ! followed by the number associated with the command I want to run in history.

    • Kelly Aster 🏳️‍⚧️English
      arrow-up
      5
      arrow-down
      0
      ·
      24 days ago
      link
      fedilink

      @papertowels@lemmy.one I’ve been working in the bash shell since 1993 and did not know sudo !! was a thing. Good lord, I no longer have to press up, press crtl-left a bunch of times, then type sudo enter space anymore. And I can give it an easy-to-remember alias like ‘resu’ or ‘redo’! Ahahaha, this changes everything! Thank you!!

      • papertowels
        arrow-up
        2
        arrow-down
        0
        ·
        23 days ago
        link
        fedilink

        We’re all learning tricks in this thread! Grateful for all y’all nerds.

    • Caveman
      arrow-up
      1
      arrow-down
      0
      ·
      24 days ago
      link
      fedilink

      Love these, I used a terminal select from history with fuzzy finding to do the !5 as redo

  • LazaroFilmEnglish
    arrow-up
    56
    arrow-down
    0
    ·
    24 days ago
    edit-2
    24 days ago
    link
    fedilink

    cd then ls then cd then ls maybe I’ll throw a ls -a

    • vrighter
      arrow-up
      13
      arrow-down
      0
      ·
      24 days ago
      link
      fedilink

      I use -A instead, which doesn’t show . and

    • papertowels
      arrow-up
      2
      arrow-down
      0
      ·
      23 days ago
      link
      fedilink

      Don’t forget your pwd thrown in to get back your bearings!

      • JackbyDevEnglish
        arrow-up
        1
        arrow-down
        0
        ·
        23 days ago
        link
        fedilink

        Done be silly, that’s part of my prompt.

  • emb
    arrow-up
    45
    arrow-down
    0
    ·
    25 days ago
    link
    fedilink

    I really like that cd command. :P

      • LalSalaamComradeEnglish
        arrow-up
        5
        arrow-down
        5
        ·
        25 days ago
        edit-2
        25 days ago
        link
        fedilink

        It’s six letters. Can’t they just call it zd or something? Yeah sure, I can use aliases, but why complicate in the first place?

          • LalSalaamComradeEnglish
            arrow-up
            8
            arrow-down
            1
            ·
            25 days ago
            link
            fedilink

            This is most probably a distro-specific aliasing. Tried it on Guix, it does not work:

            $ z
            bash: z: command not found
            
            $ zoxide
            zoxide 0.9.2
            ....
            
            • unknowing8343
              arrow-up
              5
              arrow-down
              0
              ·
              25 days ago
              link
              fedilink

              It’s in the official docs for zoxide, you are supposed to use the z alias, and many distros just set it up directly like that. I love doing z notes from wherever I am.

              • 7dev7random7
                arrow-up
                3
                arrow-down
                2
                ·
                25 days ago
                link
                fedilink

                Description fifth point (5.)

                That doesn’t require a separate package, especially one which uses eval on every new shell. And isn’t messing with my distros or personal aliases (and doesn’t introduce cargo-packaging).

                Simply adding one to two (you get the gist) directories and a keybind for cd .. is more slick. There are cases where you might use pushd . but even then other tooling should already cover your needs.

                It’s also so easy that you can temporarly append to $CDPATH for a specific session. But again, then a second pane or pushd is already available.

                Now downvote me, lemmy.

        • alsimoneau
          arrow-up
          3
          arrow-down
          0
          ·
          24 days ago
          link
          fedilink

          When you set it up you tell it which command you want. Default is “cdi” but I changed it to “cd” immediately.

    • JeenaEnglish
      arrow-up
      6
      arrow-down
      1
      ·
      25 days ago
      link
      fedilink

      Hm I wonder, is it really a command? I thought it is just a function of the shell to change the working directory.

      • ClassifiedPancake
        arrow-up
        8
        arrow-down
        0
        ·
        25 days ago
        link
        fedilink

        A command is anything you execute in the shell.

        cd is just a built-in command

  • Jess
    arrow-up
    41
    arrow-down
    0
    ·
    24 days ago
    link
    fedilink

    tldr because I am too impatient to read through man pages or google the exact syntax for what I want to do.

    • pixelscriptEnglish
      arrow-up
      27
      arrow-down
      0
      ·
      24 days ago
      link
      fedilink

      There are exactly three kinds of manpages:

      1. Way too detailed
      2. Not nearly detailed enough
      3. There is no manpage

      I will take 1 any day over 2 or 3. Sometimes I even need 1, so I’m grateful for them.

      But holy goddamn is it awful when I just want to use a command for aguably its most common use case and the flag or option for that is lost in a crowd of 30 other switches or buried under some modal subcommand. grep helps if you already know the switch, which isn’t always.

      You could argue commands like this don’t have “arguably most common usecases”, so manpages should be completely neutral on singling out examples. But I think the existence of tl;dr is the counterargument.

      Tangent complaint: I thought the Unix philosophy was “do one thing, and do it well”? Why then do so many of these shell commands have a billion options? Mostly /s but sometimes it’s flustering.

      • wuphysics87
        arrow-up
        8
        arrow-down
        0
        ·
        24 days ago
        link
        fedilink

        tldr is the first of 4 ways I rtfm. Then -h, man, and then the arch wiki

        • vrighter
          arrow-up
          4
          arrow-down
          0
          ·
          24 days ago
          link
          fedilink

          i never use man at all. It’s just too confusing.

          • wuphysics87
            arrow-up
            5
            arrow-down
            0
            ·
            24 days ago
            link
            fedilink

            I can appreciate that. Appologies if you know this already, but just don’t like them. Here are some tips.

            It helps a lot to get title/subtitle/flag highlighting. By default man pages are hard to use simply because of how dense they are. It’s much easier to skim when you can separate the parts you are looking for up front from the text.

            Don’t forget ‘/, ‘n’, and ‘N’. First way to use man pages more effectively is to search them easily. And you can search via regex. Often I’m looking for more info on a particular flag. So I’ll press ‘/’ followed by ‘^ *-g’. For a g flag.

            Take notes on the side. It saves you time later. Your future self will thank you. And you learn a lot by skimming them.

            Man pages can be intimidating/confusing, but, imho, it’s worth training that skill. Even if you are slower up front, it’s totally worth it.

            • vrighter
              arrow-up
              2
              arrow-down
              0
              ·
              24 days ago
              edit-2
              24 days ago
              link
              fedilink

              thanks for the advice. I knew about the search feature, but sometimes the stuff you need isn’t even on the page. I have no idea how to find what I need when it’s not in “man cmdname” how am I supposed to know that the feature i want has a dedicated page?

              how could I find certain commands if i didn’t already know it was a shell builtin and not a command? It’s not like you get a manpage saying “this is not a command”. And even if i did have the idea to open the bash page, it’s still useless, because builtins are their own dedicated page. That sort of stuff. It rarely ever makes things easier for me.

              edit, it is occasionally useful phen I have already found what I want on google and just want some more in depth details.

              • wuphysics87
                arrow-up
                1
                arrow-down
                0
                ·
                24 days ago
                link
                fedilink

                Unfortunately, sometimes (often) there is no man page for what you are looking for. So if you get a page not found, that’s usually the case. You can usually find associated pages all the way at the bottom. That helps when what you are looking for isn’t a command, but a reference. I don’t remember exactly where it is, but man pages are stored in a directory. Probably /etc or /usr. You can always dump that list into fzf or use grep to search to see if there is a page for what you are looking for. It’s not a perfect system by any means, but it’s a good one to have in your toolbelt.

              • JackbyDevEnglish
                arrow-up
                1
                arrow-down
                0
                ·
                23 days ago
                link
                fedilink

                If something is a bash built-in run help blah for it’s “man page”

                But yeah, man pages tick me off. Wait until you learn that there are sometimes more than one per command. I have to Google which page is which because they’re all for specific things. man foo is the equivalent of man 1 foo. What’s annoying is that the few times I’ve seen something referenced on another page the entry usually just says something like it’s on “the relevant man page” rather than just telling you exactly which.

                • vrighter
                  arrow-up
                  1
                  arrow-down
                  0
                  ·
                  23 days ago
                  link
                  fedilink

                  ok but that still entails trying random things until i find it. If I didn’t already know it was a builtin i wouldn’t know to search there. The bash thing was just an example. I have learned this stuff since i encountered the problem. This is just me recollecting my experience of trying to use man

  • pemptagoEnglish
    arrow-up
    39
    arrow-down
    0
    ·
    24 days ago
    link
    fedilink

    I went a little overboard and wrote a one-liner to accurately answer this question

    history|cut -d " " -f 5|sort|uniq -c|sort -nr|head -5
    

    Note: history displays like this for me 20622 2023-02-18 16:41:23 ls I don’t know if that’s because I set HISTTIMEFORMAT='%F %T ' in .bashrc, or if it’s like that for everyone. If it’s different for you change -f 5 to target the command. Use -f 5-7 to include flags and arguments.

    My top 5 (since last install)

       2002 ls
       1296 cd
        455 hx
        427 g
        316 find
    

    g is an alias for gitui. When I include flags and arguments most of the top commands are aliases, often shortcuts to a project directory.

    Not to ramble, but after doing this I figured I should alias the longest, most-used commands (even aliasing ls to l could have saved 2002 keystrokes :P) So I wrote another one-liner to check for available single characters to alias with:

    for c in a b c d e f g h i j k l m n o p q r s t u v w x y z; do [[ ! $(command -v $c) ]] && echo $c; done
    

    In .bash_aliases I’ve added alias b='hx ${HOME}/.bash_aliases' to quickly edit aliases and alias r='source ${HOME}/.bashrc' to reload them.

      • pemptagoEnglish
        arrow-up
        6
        arrow-down
        0
        ·
        24 days ago
        link
        fedilink

        Yup! Migrated from VSCodium; wanted to learn a modal editor but didn’t have the time or confidence to configure vim or neovim. It’s been my go-to editor for 2+ years now.

        • MigratingtoLemmyEnglish
          arrow-up
          4
          arrow-down
          0
          ·
          24 days ago
          link
          fedilink

          I’ve been using vi (just the basics) for ~4 years, I don’t think I could be arsed to pick up the keybindings the other way around lol. I’ve heard very good things about Helix, of course

          • HeartyOfGlassEnglish
            arrow-up
            3
            arrow-down
            0
            ·
            24 days ago
            link
            fedilink

            As another longtime Vi user - I had a hell of a time & wound up switching back lol

            I think for a lot of folks Helix would be intuitive. Vi has her hooks in me, though.

  • renzev
    arrow-up
    38
    arrow-down
    0
    ·
    24 days ago
    link
    fedilink

    tldr is great. Basically a crowd-sourced alternative to man with much more concise entries. Example:

    $ tldr dhcpcd
    
      DHCP client.
      More information: <https://roy.marples.name/projects/dhcpcd>.
    
      Release all address leases:
    
          sudo dhcpcd --release
    
      Request the DHCP server for new leases:
    
          sudo dhcpcd --rebind
    
  • I_Miss_DanielEnglish
    arrow-up
    38
    arrow-down
    0
    ·
    25 days ago
    link
    fedilink

    sudo udevadm monitor

    Figuring out which usb device went on holiday.

    • tetris11
      arrow-up
      8
      arrow-down
      0
      ·
      25 days ago
      link
      fedilink

      Wow, super useful command. Starring this comment

  • SinkingLotus English
    arrow-up
    37
    arrow-down
    0
    ·
    25 days ago
    link
    fedilink

    Sudo !!

    It reruns the last command as sudo.

    Pretty useful since I’m always forgetting.

  • umbrella
    arrow-up
    36
    arrow-down
    0
    ·
    25 days ago
    link
    fedilink

    control+R

    in bash, it lets you quickly search for previously executed commands.

    its very useful and makes things much quicker, i recommend you give it a try.

      • huf [he/him]English
        arrow-up
        2
        arrow-down
        0
        ·
        24 days ago
        link
        fedilink

        i rely on this in my job. if i really need it, i’ll be using it often enough that it’ll always be in ^R distance :)

  • notfromhere
    arrow-up
    33
    arrow-down
    1
    ·
    25 days ago
    link
    fedilink

    Since nobody has said yet, I use screen pretty heavily. Want to run a long running task, starting it from your phone? Run screen to create a detachable session then the long running command. You can then safely close out of your terminal or detach with ctrl a, d and continue in your terminal doing something else. screen -r to get back to it.

    • sgtlion [any]English
      arrow-up
      9
      arrow-down
      0
      ·
      25 days ago
      link
      fedilink

      I would know this as tmux, is there a difference?

      • huf [he/him]English
        arrow-up
        8
        arrow-down
        0
        ·
        25 days ago
        link
        fedilink

        no, tmux is a newer screen. some of us havent switched cos we’re too lazy i guess? i think the common wisdom is that it’s better. i havent tried cos i already know enough of screen and it’s fine for me

        • papertowels
          arrow-up
          7
          arrow-down
          0
          ·
          25 days ago
          link
          fedilink

          Or you can learn both and spend the rest of your life trying screen commands in tmux and vice versa.

      • naught
        arrow-up
        1
        arrow-down
        0
        ·
        25 days ago
        link
        fedilink

        gnu screen is just a different program than tmux. they do the same thing though

    • gitamarDeutsch
      arrow-up
      8
      arrow-down
      0
      ·
      25 days ago
      link
      fedilink

      I recently switched to tmux and boy, it’s way better. I basically use only tmux now anymore. Creating panes to have two processes in one glance, multiple windows, awesome. Plus all the benefits of screen.

      • krash
        arrow-up
        4
        arrow-down
        0
        ·
        25 days ago
        link
        fedilink

        Try zellij. Not as popular as tmux, but very intuitive to use.

      • 7dev7random7
        arrow-up
        2
        arrow-down
        0
        ·
        25 days ago
        link
        fedilink

        Maybe someone reading wants to now about prefix+s. This doubles your excitement.

    • papertowels
      arrow-up
      7
      arrow-down
      0
      ·
      25 days ago
      link
      fedilink

      In a similar vein, nohup lets you send tasks to the background and seems to be everywhere.

      • pyr0ball
        arrow-up
        3
        arrow-down
        0
        ·
        24 days ago
        link
        fedilink

        You can’t mention nohup without at least mentioning kill -9 or pkill to slay the monster you created you madman

        • papertowels
          arrow-up
          2
          arrow-down
          0
          ·
          24 days ago
          link
          fedilink

          Sometimes I’ll just reboot the entire damn machine just to be safe ;)

        • Caveman
          arrow-up
          1
          arrow-down
          0
          ·
          24 days ago
          link
          fedilink

          Eyyy, don’t hate, this is how I start all my work programs. That command is really nice and creates all work programs as children of a single terminal session for easy closing later.

          • pyr0ball
            arrow-up
            2
            arrow-down
            0
            ·
            24 days ago
            link
            fedilink

            No hate! Just need to make sure people know so they don’t create a bazillion threads without realizing it, or how to stop them effectively

    • tetris11
      arrow-up
      4
      arrow-down
      0
      ·
      25 days ago
      link
      fedilink

      Also, screen can connect to an UART device or serial or anything that offers up a TTY

    • muzzle
      arrow-up
      2
      arrow-down
      0
      ·
      25 days ago
      link
      fedilink

      I Always forget to run screen first, so I just rely heavily on dtach

      • 7dev7random7
        arrow-up
        1
        arrow-down
        0
        ·
        25 days ago
        link
        fedilink

        Simply change your terminal command to execute the terminal multiplexer of your choice.

        man terminal_of_choice, look for (start) command.

    • krash
      arrow-up
      1
      arrow-down
      0
      ·
      25 days ago
      link
      fedilink

      How does screen / tmux work when detached from a session, how does it keep the session alive (both when running locally, and while ssh:ing to a server)? Is there a daemon involved?

      • darvit
        arrow-up
        1
        arrow-down
        0
        ·
        24 days ago
        link
        fedilink

        You can find out by running screen and executing pstree, that way you can see how the screen process is run.

  • zlatiah
    arrow-up
    31
    arrow-down
    0
    ·
    24 days ago
    link
    fedilink

    clear because apparently I am too scatterbrained to comprehend more than one full page of text in the terminal

    • feddylemmy
      arrow-up
      6
      arrow-down
      0
      ·
      24 days ago
      link
      fedilink

      I like using CRTL+L to clear. It’s nice because you can have a command typed out and still be able to press CTRL+L to clear the screen and keep the command typed out.

    • mexicancartelEnglish
      arrow-up
      4
      arrow-down
      0
      ·
      24 days ago
      link
      fedilink

      I almost never use clear because i’m afraid if i will need the text later.(just like infinity tab number on firefox)

        • zlatiah
          arrow-up
          1
          arrow-down
          0
          ·
          24 days ago
          edit-2
          24 days ago
          link
          fedilink

          Oh god I also do this See the comment below, I ran history|cut -d " " -f 5|sort|uniq -c|sort -nr|less on my personal laptop, my third most commonly used command (behind ls and cd) is just typing in nothing

      • BaumGeist
        arrow-up
        1
        arrow-down
        0
        ·
        24 days ago
        link
        fedilink

        Use script instead, you can even have it in your .*shrc to run automatically whenever a shell is invoked (make sure to add a check that the shell wasn’t invoked by script, so you don’t inadvertently forkbomb yourself)

        Alternatively, just use Terminator as yout terminal emulator and enable the logger anytime you need it to record the shell session.

        Also, use bookmarks. That’s what they’re there for. 100 tabs is a great way to clutter your brain, but terrible for productivity. If you forget about it after bookmarking, it wasn’t important to begin with.

        • mexicancartelEnglish
          arrow-up
          1
          arrow-down
          0
          ·
          23 days ago
          link
          fedilink

          100 tabs is in mobile. I don’t even scroll back to clutter my brain but its there. Tabs are history for me So I use firefox focus and if there is anything important, i open with firefox.

          What script are you reffering to? To log all output? I don’t wanna store that but need an assurance that its there till i close terminal window lol

  • BougieBirdieEnglish
    arrow-up
    27
    arrow-down
    1
    ·
    25 days ago
    link
    fedilink

    Not a specific command, but I learned recently you can just dump any executable script into ~/bin and run it from the terminal.

    I suffer greatly from analysis paralysis, I have a very hard time making decisions especially if there’s many options. So I wrote a script that reads a text file full of tasks and just picks one. It took me like ten minutes to write and now I spend far more time doing stuff instead of doing nothing and feeling badly that I can’t decide what to do.

    • friend_of_satanEnglish
      arrow-up
      23
      arrow-down
      0
      ·
      25 days ago
      link
      fedilink

      This is because $HOME/bin is in your $PATH environment variable. You can add more paths that you’d like to execute scripts from, like a personal git repo that contains your scripts.

    • unknowing8343
      arrow-up
      19
      arrow-down
      0
      ·
      25 days ago
      link
      fedilink

      I think the standard is ~/.local/bin, for the people that like standards.

  • itsame
    arrow-up
    25
    arrow-down
    0
    ·
    25 days ago
    link
    fedilink

    pushd and popd to change directory and go back when done there.

    • jbrains
      arrow-up
      4
      arrow-down
      0
      ·
      25 days ago
      link
      fedilink

      Even better when cd automatically invokes pushd.

      • lluki
        arrow-up
        29
        arrow-down
        0
        ·
        25 days ago
        link
        fedilink

        cd - undoes the last cd. Not quite push/popd but still useful. Pro tip, works also: git checkout -

        • med
          arrow-up
          4
          arrow-down
          0
          ·
          25 days ago
          link
          fedilink

          Hell yeah. Every one of these threads makes me more inclined to read man pages

          • 7dev7random7
            arrow-up
            2
            arrow-down
            0
            ·
            25 days ago
            link
            fedilink

            You should. These are the actually sources to learn.

  • LambdaRX
    arrow-up
    24
    arrow-down
    0
    ·
    25 days ago
    edit-2
    25 days ago
    link
    fedilink

    After using too much WINE, I type pwd, whoami

      • HeartyOfGlassEnglish
        arrow-up
        26
        arrow-down
        0
        ·
        25 days ago
        link
        fedilink

        Oh. I know. But you don’t understand - I’m compelled to type it out. I must.

        • ripcord
          arrow-up
          1
          arrow-down
          0
          ·
          25 days ago
          link
          fedilink

          I used to, but the terminal clear is better, so I don’t.

        • 7dev7random7
          arrow-up
          1
          arrow-down
          0
          ·
          25 days ago
          link
          fedilink

          Someone who doesn’t know the benefits of dedicated, unlimited scrollback buffers. This command is useful but has a bad effect (when unintentionally).

          • ripcord
            arrow-up
            2
            arrow-down
            0
            ·
            24 days ago
            link
            fedilink

            No, I do. Clearing the scrollback because I want a new, very clear start point for a new activity and don’t care about the rest is frequently the goal.

            If I do care about the history I’ll do something else or possibly been saving history to disk, although that’s far more rare.

    • omxxiEnglish
      arrow-up
      1
      arrow-down
      0
      ·
      23 days ago
      link
      fedilink

      haha, I can relate to that :). formerly I had the compulsion to execute sync frequently. Now my compulsion is to push Ctrl-C like 4 times every time I need it. I read somewhere that’s common because of ^C has a lack of feedback to the user, so, a script showing an alert that the clipboard received some information helped with this compulsion.

    • Pup BiruEnglish
      arrow-up
      1
      arrow-down
      0
      ·
      24 days ago
      link
      fedilink

      i’d like to introduce you to your new best friend: reset it doesn’t everything clear does and a LOT more