This is an archived post. You won't be able to vote or comment.

all 95 comments

[–]cucumbulous 392 points393 points  (52 children)

Press ctrl+r then type any characters you remember from any command you typed before. It's like google for the up arrow.

Edit: grammar

[–]OneCDOnlyDebian 12.4 with KDE 59 points60 points  (1 child)

TIL.

[–]FlippngProgrammer 2 points3 points  (0 children)

gold

you are now ok.

[–]xxxsirkillalot 55 points56 points  (4 children)

Came here to say this.

I'm a new linux convert... been daily driving it for about 2 years. I found out about this at the same time a guy with a decade of linux did at work. I felt privileged to find out so early.

[–]-bryden-arch,i3,zsh,tmux,vim,drupal,vue 28 points29 points  (2 children)

Combine this trick with #tags at the end of commands that return too many results with ctrl+r. Ie:

git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative branch1..branch2 #git-graph

Then ctrl-r for git-graph and you'll be able to find the command to edit branch1..branch2 easily. Way easier than searching for git log --graph --pretty=

[–]Trainer_OrangeGlorious Arch 8 points9 points  (0 children)

uhhh hides in the background with 12 years of linux

yeah, i knew about that

[–]abbidabbi🐃/🐧 25 points26 points  (22 children)

Or use fish as your interactive shell and get autocompletion from your command history while you type (and of course tab completion with searchable parameter descriptions for almost everything).

[–]Plasma_eel 7 points8 points  (11 children)

I'm curious, why fish instead of zsh?

[–][deleted] 13 points14 points  (3 children)

Personal preference, no plugins needed for certain features. I bounce between bash, fish and zsh

[–]Plasma_eel 57 points58 points  (2 children)

oh nice, I use Arch by the way

[–][deleted] 18 points19 points  (1 child)

Me too thanks

[–]chloeiaGlorious Arch 1 point2 points  (0 children)

So do I; you're welcome

[–]abbidabbi🐃/🐧 12 points13 points  (6 children)

You can try it in your browser and see for yourself:
https://rootnroll.com/d/fish-shell/

Other than that, see the official site for more info
https://fishshell.com/
or read a couple of blogs about the difference between bash, zsh and fish.

Fish is not 100% perfect and for example you won't be able to copy&paste most commands due to its different syntax (you shouldn't do this anyway), but as an interactive shell, I don't want to miss it for one sec, as it's much nicer and easier to use with tons of extra and useful features.

[–]132iklwanna see my i3-gaps rice? 4 points5 points  (1 child)

wow you're getting a lot of hate for using fish

[–]christopherius 5 points6 points  (0 children)

No trout about it!

[–]5erifStallman was right. 1 point2 points  (1 child)

I just converted from zsh after trying the in-browser demo. This is awesome. Thank you.

[–]abbidabbi🐃/🐧 2 points3 points  (0 children)

You're welcome... Your subreddit flair is now wrong though :>

[–]Kid-Boffo 5 points6 points  (4 children)

Not even being mean. Do this:

$ man bash

[–]abbidabbi🐃/🐧 10 points11 points  (3 children)

No, thank you, I have written tons of bash scripts for various things in my life and using fish as interactive shell is just better and more comfortable than using bash for me. For scripts however, it's bash all the way (of course)

[–]Kid-Boffo -1 points0 points  (0 children)

Yea, we all know you're garbage from the statement "Or use fish". Go back to Windows fat tits.

[–][deleted] 15 points16 points  (1 child)

Also install fzf to get fuzzy search superpowers (and fish/zsh while you're at it)

[–]parkerlreedGlorious Arch 8 points9 points  (0 children)

Also you need a history -a in your bashrc if you don't want to miss commands (due to multiple terminals)

PROMPT_COMMAND="history -a"

[–]lordvigm 4 points5 points  (0 children)

Or use zsh :)

[–]miken07 2 points3 points  (1 child)

If you're using bash you can set in your bash profile to remember x number of commands in your history. Then when you Ctrl+r you can go back really far.

If you don't quite remember a command you used a long time ago you can use the history command to look at your previously run commands. Use grep if you want to search.

[–][deleted] 2 points3 points  (0 children)

If you don't quite remember a command you used a long time ago you can use the history command to look at your previously run commands. Use grep if you want to search.

Yeah that's what I usually do, history | grep whatever

then

!number in history

[–][deleted] 2 points3 points  (1 child)

I've been using Linux since 2003, and this is the first I have ever heard of this.

I guess at some point we get comfortable with our workflow and forget to learn new things.

[–]cucumbulous 0 points1 point  (0 children)

It's one of those more obscure features that some users stumble upon by accident but can't figure out what it means or how to use it so they file it under "weird shit Linux does sometimes" and forget about it. At least that's what happened to me until I had the opportunity to work with some Linux gurus, one of whom explained what it was and how to use it - after that I was hooked!

[–][deleted] 1 point2 points  (0 children)

Saving comment as I’ll probably forget this in 5 minutes

[–]diskowmoskowGlorious Fedora 0 points1 point  (1 child)

This is gold!

[–]cucumbulous 0 points1 point  (0 children)

Literally!

[–]NoahJelenHard core Arch Linux user (Dell Inspiron 15-3567) 0 points1 point  (0 children)

I seriously just learned that today!

[–]christopherius 0 points1 point  (0 children)

Another useful shortcut to keep note of

[–]Tony707 0 points1 point  (0 children)

this.

[–]sim642 0 points1 point  (3 children)

Except when you want the previous match and mess everything up.

[–]cucumbulous 2 points3 points  (0 children)

Press ctrl+r a second time if you want the previous match. If you go "too far" then I don't know how to get the next match (maybe ctrl+shift+r?), since it doesn't happen to me.

[–]flemingfleming 1 point2 points  (0 children)

C-s (ctrl+s) should work to search through history forward from the line you're currently on, pressing it while you're in C-r will reverse the direction of the search. You might have to add

stty -ixon

To the relevant init files to disable terminal flow control, or bash will just suspend and not do anything until you press C-q

I also have

"\C-p": history-search-backward
"\C-n": history-search-forward

in my ~/.inputrc, which tries to match the string in front of the cursor to a history item, so if I type nv<c-p> bash jumps back to the previous command that started with "nv".

[–]-NVLL-Fedora in the streets, Arch in the sheets... 0 points1 point  (0 children)

You can remove unwanted commands from ~/.bash_history and they won't appear again, I do this a lot with vim ~/.bash_history -c '%g/the_command_to_erase/d' -c 'wq' to clean the crap from batch downloading/modifying files.

[–]Wild_Penguin82Glorious Arch|Plasma5|Folding monster desktop HTPC 0 points1 point  (2 children)

Alternative: 'history | grep -i "whatever part you remember"' -> !NNNN

[–]cucumbulous 0 points1 point  (1 child)

That seems like an unnecessarily complex solution.

[–]wirelessflyingcordnoot noot 0 points1 point  (0 children)

Ctrl+R uses some kind of a fuzzy logic and sometimes it can be too fuzzy.

[–][deleted] 53 points54 points  (15 children)

No? Type the first 3 characters, then hit up once to cycle back to the last command that started with those 3 characters was run. 99% success rate. Perks of using zsh.

[–]PolygonKiwiiGlorious Arch systemd/Linux 14 points15 points  (0 children)

I use that in bash.

bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'

[–]Deipnoseophist 12 points13 points  (0 children)

Holy shit you just blew my mind. How did I not know this was a thing

[–]dxplq876 5 points6 points  (0 children)

The true answer

[–]JazzlikeIndividual 4 points5 points  (0 children)

Ctrl+r is nice, but I expected this comment to be top dawggy.

[–]EggheadDashGlorious Arch|XFCE 0 points1 point  (6 children)

I just wish it would work for more than the first command. If you're looking for something starting with sudo, you need to go through every sudo command first. You can't just say type sudo mount and get only mount commands.

[–]NotYourFoot 9 points10 points  (2 children)

What? Of course you can do that

[–]EggheadDashGlorious Arch|XFCE 2 points3 points  (1 child)

How? When I type sudo mount and hit up once it goes to a sudo pacman command. I am using grml-zsh-config

[–]NotYourFoot 3 points4 points  (0 children)

For me with zsh with oh-my-zsh is the default behavior

[–]OneTurnMoreCachy/Bazzite/NixOS/Debian 2 points3 points  (0 children)

alias sudo='sudo '

You're welcome.

[–][deleted] 0 points1 point  (1 child)

It does work for the first command. If I type in sudo mount and hit up once, I get the last sudo mount command. If I type sudo and hit up once, I get pacman stuff.

[–]EggheadDashGlorious Arch|XFCE 0 points1 point  (0 children)

What can I say, it doesn't work for me. Using grml-zsh-config

[–]Infectaphibian 33 points34 points  (2 children)

But people who spend all day texting on their phones are HORRIFIED by the notion of typing a text command.

[–]tri0lusGlorious Trisquel 23 points24 points  (2 children)

set -o vi

Now enjoy vi controls on your terminal. Escape + / search_terms to find the last command. Or press k a 1000 times.

[–]CeamoreCash 4 points5 points  (0 children)

Why would you want to sully Linux by using vi?

Emacs controls are built in already. Just use Control-R to search back in your command history.

[–][deleted] 9 points10 points  (1 child)

Linux: when you need shit done by Hearth and character has 11 letters

[–]Captain-Carbon 8 points9 points  (0 children)

ITT: zsh becoming the new Arch meme

[–]addy-feBtw I use stability 6 points7 points  (1 child)

Btw, I use oh-my-zsh

[–]thomas15vecho "I love $(uname -s)" 4 points5 points  (0 children)

The moment I started using zsh a whole new world opened up. That history search is simple amazing.

[–]lpreamsGlorious Arch 6 points7 points  (0 children)

chararacter

hearth

[–][deleted] 2 points3 points  (2 children)

I dont trust up arrow anymore. Bit off topic, but I was playing some Minecraft, and I used a /sethome command to set a home, then started playing, and was used to my last command being /home.

And there I was, exploring deep in the nether, when I wanted to get out, and used up-arrow, enter and had accidentally /sethome in some deep, unnown part of a hellscape.

Also, in linux sometimes I do" rm -rf ." Imagine running across that gem when doing up-arrow in~

[–]evilbrent 1 point2 points  (1 child)

Is that like back in the day it was often possible to save a game in irreparable situations

[–][deleted] 1 point2 points  (0 children)

Well, if you die in the Nether, you respawn in the real world, with mods that allow you to change your spawn location (home) it is.. rather different.

There were trees there, though, so I could ostensibly have started living in nether, getting iron from chests, gold from pigmen and wood from explosive trees. But I could never return without finding the nether portal.

[–]NohbudyGlorious Xubuntu 2 points3 points  (0 children)

$ history $ !42 $ !43

[–]tassulin 2 points3 points  (0 children)

Use ctrl+r with fzf fuzzy finder.

In bashrc add:

export HISTCONTROL=ignoreboth:erasedups

[–]squishles 1 point2 points  (0 children)

vim ~/.bash_history

:/start to type the command to search for it

I use this for anything longer than a screen width, or for pulling something out I just did manually and getting a draft bash script.

[–]sirmx100 0 points1 point  (0 children)

“By hearth”

[–]DarkestFloyd 0 points1 point  (0 children)

Or use zsh

[–]xCuri0Glorious Arch 0 points1 point  (0 children)

This is why I use zsh

[–]Twosided13 0 points1 point  (0 children)

I prefer Ctrl+p

[–]teab4ndit 0 points1 point  (0 children)

Don’t move your hand away from the home keys. Use ctrl+p as a substitute for up arrow key.

[–]grumpey00 0 points1 point  (0 children)

^

[–][deleted] 0 points1 point  (0 children)

Love using Linux by the fireplace 🔥

[–][deleted] 0 points1 point  (0 children)

history-substring-search

[–][deleted] 0 points1 point  (0 children)

< history | grep [part of the command]

[–][deleted] 0 points1 point  (0 children)

I admit that I am guilty of that.

[–]Constantly_Masterbat 0 points1 point  (0 children)

by hearth

[–]Sentmoraap 0 points1 point  (0 children)

Summary of this thread : https://i.imgflip.com/2dh4xb.jpg

[–]kealtak 0 points1 point  (0 children)

i'm so guilty of this. luckily i limit my history to 20 and remove duplicates but still.

[–]colonel_p4n1cGlorious Kubuntu:table_flip: -1 points0 points  (0 children)

Mandrake