• papertowels@lemmy.one
    ·
    1 month ago

    sudo !! to rerun last command as sudo.

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

      • papertowels@lemmy.one
        ·
        edit-2
        1 month ago

        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.

  • notfromhere@lemmy.ml
    ·
    1 month ago

    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]
      ·
      1 month ago

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

      • huf [he/him]
        ·
        1 month ago

        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

    • tetris11@lemmy.ml
      ·
      1 month ago

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

    • krash@lemmy.ml
      ·
      1 month ago

      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?

  • pemptago@lemmy.ml
    ·
    1 month ago

    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.

  • umbrella@lemmy.ml
    ·
    1 month ago

    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]
        ·
        1 month ago

        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 :)

  • sgtnasty@lemmy.ml
    ·
    1 month ago

    pv (Pipe Viewer) is a command line tool to view verbose information about data streamed/piped through it. The data can be of any source like files, block devices, network streams etc. It shows the amount of data passed through, time running, progress bar, percentage and the estimated completion time.

      • sp451@lemmy.sdf.org
        ·
        1 month ago

        Agree. Don’t just copy and paste CLI commands you find on the internet, suggested by a stranger

      • Hux@lemmy.ml
        ·
        1 month ago

        For reference: https://en.m.wikipedia.org/wiki/Rm_(Unix)

        The rm -rf / variant of the command, if run by a superuser, would cause every file accessible from the present file system to be deleted from the machine.

      • huf [he/him]
        ·
        1 month ago

        doesnt actually do anything on gnu rm, and hasnt in like a decade. but yeah, dont do it.

  • squid_slime@lemm.ee
    ·
    1 month ago

    du -sh /too/bar to get size of files/folders. sudo !! inserts sudo into previous command when forgotten. yay for full system update if yay is installed. cat reads files.

  • Korthrun@lemmy.sdf.org
    ·
    1 month ago

    Seems like an appropriate place to share https://github.com/agarrharr/awesome-cli-apps

    I'm a fan of ripgrep and lsd in particular.

  • NauticalNoodle@lemmy.ml
    ·
    edit-2
    1 month ago

    For Debian based/descended distros:

    sudo apt-get update && sudo apt-get upgrade
    

    And technically I also regularly use

    redshift -O 3000
    

    all of the blue light filter programs try to align themselves with a user's geographic location and time, but I don't keep normal hours

      • NauticalNoodle@lemmy.ml
        ·
        1 month ago

        I would but much like somebody else's recent post I have in the past nuked my install by blindly agreeing to some recommended software removals before. These days I like to double check what packages are being updated and replaced.