• ch00f@lemmy.world
        link
        fedilink
        arrow-up
        40
        ·
        4 months ago

        Shit is usually a pain in the ass. The challenge is divining how much of a pain in the ass something has to be that someone else might have made a solution for it.

        I didn’t know you could ctrl+shift+c to copy in the terminal until a month ago when my linux n00b wife said "there has to be a better way to do this. I’ve been right clicking to copy for 10 years.

      • grrgyle@slrpnk.net
        link
        fedilink
        arrow-up
        11
        ·
        4 months ago

        Congratulations! I remember where I was when I first learned it (in a noisy server room at the back of a machine shop).

        Now pair it with FZF for fuzzy finding – it’s surprisingly easy to set up, just following any guide. It’s insanely useful. I find myself even doing things like typing:

        $ xinput --disable $(xinput --list | grep -i touchpad | grep 'id=[0-9]\+' -o | cut -d= -f2)  # Disable synaptic touchpad trackpad pointer
        

        commands with these like comments on the ends as sort of “tags” so I can ctrl+r search for them later. Yes, I know I could just use a named function, but this is like the step just before that–before I know if I’ll be issuing the same command all the time, or just for the next couple weeks. (This one was from when I was resting my notebook on my laptop.)

        • oddlyqueer@lemmy.ml
          link
          fedilink
          English
          arrow-up
          5
          ·
          4 months ago

          I like this; I have a lot of commands that I don’t use often enough to justify an alias, but still need to rerun all the time. thanks!

      • lmmarsano@lemmynsfw.com
        link
        fedilink
        English
        arrow-up
        8
        ·
        edit-2
        4 months ago

        As usual, that’s documented (we can RTFM).

        Before trying ctrl-s, you may want to disable software flow control: run stty -ixon & add it to your initialization files. Otherwise, you’ll pause terminal output. ctrl-q resumes terminal output.

        stty reveals terminal special characters

        $ stty -a
        ⁝
        intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; …
        ⁝
        

        These special characters/keys often perform special functions. To illustrate

        • ctrl-d on empty input typically exits/logs out of interactive terminal applications (including shells)
        • ctrl-u discards input (useful for inputs like password prompts that don’t echo input back)
        • ctrl-v inputs next character literally (such as tab)
      • Dave@lemmy.nz
        link
        fedilink
        arrow-up
        6
        ·
        4 months ago

        Just checking, because I learnt to type before I worked this out, and because surely someone reading doesn’t know: press tab. Bash will fill in file names from your current directory.

        E.g. say you have files fred1file, fred2file, jim.

        Type f then press tab, it will fill to “fred”. Then press 2 and press tab again and it will fill the full “fred2file”.

        Have a play, it works in heaps of situations.

        • bobo@lemmy.world
          link
          fedilink
          arrow-up
          2
          ·
          edit-2
          4 months ago

          Bash will also do autocomplete for cli programs that have autocomplete functionality. Try typing:

          git r<tab><tab>

          you’ll see options for all the git commands that start with r. Often cli commands will have autocompletion for long (double dash) options.

          If you want to see all the commands that have auto complete available, look in:

          /usr/share/bash-completion/completions/

          There’s a few other locations they can live, notably:

          /etc/bash_completion.d/ ~/.bash_completion ~/.local/share/bash-completion/completions/

          I don’t know if there are more or if there is any variation per distro.

          You can also write your own bash completions. They can get pretty smart and context sensitive.

          Pretty good beginning tutorial:

          https://iridakos.com/programming/2018/03/01/bash-programmable-completion-tutorial

          edit - I should’ve mentioned that this isn’t native to bash, it requires installation of bash-completion. But bash-completion is installed by default in many distros.

    • Cenzorrll@lemmy.world
      link
      fedilink
      arrow-up
      12
      ·
      edit-2
      4 months ago

      I’m not going to say how long I used linux before learning this. It isn’t “this many days old”, but it may as well be.

      I have 7 headless linux boxes running.

    • Damage@feddit.it
      link
      fedilink
      arrow-up
      8
      ·
      4 months ago

      Even quicker with zsh or atuin: write the first few letters then arrow up to cycle through all matches

      • Ephera@lemmy.ml
        link
        fedilink
        English
        arrow-up
        7
        ·
        4 months ago

        Even quicker with fish: Write the first few letters then it auto-suggests the last-run command matching that prefix (and then you can still arrow up to cycle through all matches).

        (There is also a zsh plugin for that, called zsh-autosuggestions.)

    • Jankatarch@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      4 months ago

      I like to imagine someone added it in for their own personal use and told nobody because surely they are the only one.

    • Mikelius@lemmy.ml
      link
      fedilink
      arrow-up
      1
      ·
      4 months ago

      I’m shocked how far I had to scroll down before it was mentioned, I was getting scared I would have to say it lol

  • bdonvr@thelemmy.club
    link
    fedilink
    arrow-up
    70
    ·
    edit-2
    4 months ago

    I used to be like this but people seriously. CTRL+R

    Do it. Don’t make this one of those things you’ve heard about and just never got around to trying. Open your terminal right now and CTRL+R and type any part of the command you did before. If the command you want is not showing first just hit CTRL+R again to go to the next one back.

    DO IT.

    Edit: I did learn from this thread today though that ZSH has it set to where you can just type part of what you’re looking for then hit up to do the same thing. Neat!

  • PhAzE@lemmy.ca
    link
    fedilink
    arrow-up
    28
    ·
    edit-2
    4 months ago

    Ctrl + R and start typing the command, it’ll come up, press enter. Im just more lazy because I know there are still faster ways.

    Edit: instead of hitting enter, keep pressing ctrl + R to cycle through history commands that contain what you typed in

  • Iced Raktajino@startrek.website
    link
    fedilink
    arrow-up
    22
    ·
    edit-2
    4 months ago

    Pretty much, yeah.

    Rather than jot down in a text file the various ffmpeg commands I use frequently…

    Raktajino@laptop:~/Downloads$ history | grep ffmpeg
       12  sudo apt install audacity gimp ffmpeg mplayer
      184  history | grep ffmpeg
      215  ffmpeg -i source.mkv -ss 629 -t 7 out.mkv
      217  ffmpeg -i out.mkv -s 0.5 -vf scale=1280:720 out.mp4
      218  ffmpeg -i out.mkv -ss 0.5 -vf scale=1280:720 out.mp4
      231  ffmpeg -i out.mp4 -vf "subtitles=out.srt" final.mp4
      503  ffmpeg -i toofat.wav toofat.mp3
      ...
      682  history | grep ffmpeg
      684  ffmpeg -i 1.gif -i 2.gif -filter_complex "[1:0] [2:0] concat=n=2" out.gif
      685  ffmpeg -i 1.gif -i 2.gif -filter_complex "[1:0] [2:0] concat=n=2:v=1" out.gif
      686  ffmpeg -i 1.gif -i 2.gif -filter_complex "[1:0] [2:0] concat=n=2:v=1" -map '[v]' out.gif
      687  history | grep ffmpeg
      688  ffmpeg -i 1.gif -i 2.gif -filter_complex "[0:0] 12:0] concat=n=2:v=1" -map '[v]' out.gif
      689  ffmpeg -i 1.gif -i 2.gif -filter_complex "[0:0] 1:0] concat=n=2:v=1" -map '[v]' out.gif
      690  ffmpeg -i 1.gif -i 2.gif -filter_complex "[0:0] [1:0] concat=n=2:v=1" -map '[v]' out.gif
      691  ffmpeg -i 1.gif -i 2.gif -filter_complex "[0:0] [1:0] concat=n=2"  out.gif
      694  history | grep ffmpeg
    
    • apftwb@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      edit-2
      4 months ago

      ⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️

      CTL+C

      history

      history | less

      ⬆️⬆️⬆️

      Pg-up

      Pg-up

      q

      ! 2648

      • Lebernashi@lemmy.world
        link
        fedilink
        arrow-up
        9
        ·
        4 months ago

        Every time you hit the up arrow, it shows the previous command you used in the terminal.

        So hitting the arrow once gives your last used, hitting it twice gives your second to last command, and so on.

        • djvinniev77@lemmy.ca
          link
          fedilink
          arrow-up
          3
          ·
          4 months ago

          Yup and that is me. I could just history grep the command I want but I SWEAR it was just 2 commands ago, or 15 up arrows. lol.

          • Jarix@lemmy.world
            link
            fedilink
            arrow-up
            2
            ·
            edit-2
            4 months ago

            Ohhh! I can absolutely relate to this as well! Using a zmud client to play games on. which is probably not much different, looking, than a terminal anyways

              • Jarix@lemmy.world
                link
                fedilink
                arrow-up
                1
                ·
                3 months ago

                Did. It’s long gone

                Was a modified circlemud. Mostly fantasy. Was a mish mash of popular fantasy worlds. Feist, Tolkien, various DnD settings, letter on they tried to go away from fandom content.

                Had any 29 classes, could “remort” keeping 15% of your skills. And had other benefits such as lowering some level requirements here and there.

                Was riftsmud.net:4000 originally but they ended up having to move a could times.

                About 40 players at peak times, maybe 100 players altogether that played any amount

  • JATth@lemmy.world
    link
    fedilink
    English
    arrow-up
    11
    ·
    4 months ago

    zsh-history-substring-search

    I lazily type part of the thing I want like “sys” and then ctrl+⬆️/⬇️ and sudo systemctl start libvirtd etc. appear like magic.